Add debug

This commit is contained in:
jheaps
2025-05-27 10:40:27 -06:00
parent ed35a2e86f
commit 824a1d6eab
5 changed files with 169 additions and 115 deletions
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace JoshHeaps.Net.Controllers;
[ApiController]
[Route("api/[controller]")]
public class DebugController : ControllerBase
{
[HttpGet("IpCheck")]
public ActionResult<string> GetIpCheckingStatus()
{
return Ok(Program.CheckingForIpUpdates.ToString());
}
}
+3 -1
View File
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
@@ -11,7 +11,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="wwwroot\css\debug\" />
<Folder Include="wwwroot\images\Chess Images\" /> <Folder Include="wwwroot\images\Chess Images\" />
<Folder Include="wwwroot\images\Game Images\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
+15
View File
@@ -0,0 +1,15 @@
@page
@model JoshHeaps.Net.Pages.GameModel
@{
ViewData["Title"] = "Game";
Layout = "_Layout";
}
<div id="IpChecking">
<label id="IpCheckingLabel">Is checking for ip updates:</label>
<div id="IsIpChecking">...</div>
</div>
@section Scripts {
<script src="~/js/Debug/debug.js"></script>
}
+11
View File
@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace JoshHeaps.Net.Pages
{
public class DebugModel : PageModel
{
public void OnGet()
{
}
}
}
+51 -39
View File
@@ -2,58 +2,69 @@ using JoshHeaps.Net.Hubs;
using JoshHeaps.Net.Services.Implementations; using JoshHeaps.Net.Services.Implementations;
using JoshHeaps.Net.Services.Interfaces; using JoshHeaps.Net.Services.Interfaces;
var builder = WebApplication.CreateBuilder(args); namespace JoshHeaps.Net;
// Add services to the container. // need to declare the class so I can add the public static bool
builder.Services.AddRazorPages(); public class Program
var configuration = builder.Configuration; {
Task updateIpTask; public static bool CheckingForIpUpdates { get; private set; } = false;
if (!builder.Environment.IsDevelopment()) public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
var configuration = builder.Configuration;
Task updateIpTask;
if (!builder.Environment.IsDevelopment())
updateIpTask = Run(configuration); updateIpTask = Run(configuration);
builder.Services.AddControllers(); builder.Services.AddControllers();
builder.Services.AddSignalR(); builder.Services.AddSignalR();
builder.Services.AddSingleton<IChessService, ChessService>(); builder.Services.AddSingleton<IChessService, ChessService>();
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment()) if (!app.Environment.IsDevelopment())
{ {
app.UseExceptionHandler("/Error"); app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts(); app.UseHsts();
} }
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseStaticFiles(new StaticFileOptions app.UseStaticFiles(new StaticFileOptions
{ {
OnPrepareResponse = ctx => OnPrepareResponse = ctx =>
{ {
ctx.Context.Response.Headers.Append("Cache-Control", "no-cache, no-store, must-revalidate"); ctx.Context.Response.Headers.Append("Cache-Control", "no-cache, no-store, must-revalidate");
ctx.Context.Response.Headers.Append("Pragma", "no-cache"); ctx.Context.Response.Headers.Append("Pragma", "no-cache");
ctx.Context.Response.Headers.Append("Expires", "0"); ctx.Context.Response.Headers.Append("Expires", "0");
} }
}); });
app.UseRouting(); app.UseRouting();
app.UseAuthorization(); app.UseAuthorization();
app.MapRazorPages(); app.MapRazorPages();
app.MapControllers(); app.MapControllers();
app.MapHub<ChessHub>("/chessHub"); app.MapHub<ChessHub>("/chessHub");
app.Run(); app.Run();
}
static async Task Run(IConfiguration config) static async Task Run(IConfiguration config)
{ {
CheckingForIpUpdates = true;
HttpClient httpClient = new(); HttpClient httpClient = new();
AAAARecord dnsRecord = await GetDnsRecordAsync(config); AAAARecord dnsRecord = await GetDnsRecordAsync(config);
string lastKnownIp = dnsRecord.content; string lastKnownIp = dnsRecord.content;
@@ -79,10 +90,10 @@ static async Task Run(IConfiguration config)
await Task.Delay(checkInterval); await Task.Delay(checkInterval);
} }
} }
static async Task<string> GetPublicIpAsync(HttpClient client) static async Task<string> GetPublicIpAsync(HttpClient client)
{ {
try try
{ {
return await client.GetStringAsync(@"https://api.ipify.org/"); return await client.GetStringAsync(@"https://api.ipify.org/");
@@ -94,10 +105,10 @@ static async Task<string> GetPublicIpAsync(HttpClient client)
return await GetPublicIpAsync(client); return await GetPublicIpAsync(client);
} }
} }
static async Task<AAAARecord> GetDnsRecordAsync(IConfiguration config) static async Task<AAAARecord> GetDnsRecordAsync(IConfiguration config)
{ {
try try
{ {
HttpClient cfClient = new(); HttpClient cfClient = new();
@@ -115,10 +126,10 @@ static async Task<AAAARecord> GetDnsRecordAsync(IConfiguration config)
return await GetDnsRecordAsync(config); return await GetDnsRecordAsync(config);
} }
} }
static async Task UpdateDnsIpAsync(IConfiguration config, AAAARecord record, string ip) static async Task UpdateDnsIpAsync(IConfiguration config, AAAARecord record, string ip)
{ {
HttpClient cfClient = new(); HttpClient cfClient = new();
cfClient.DefaultRequestHeaders.Add("X-Auth-Email", config["cfEmail"]); cfClient.DefaultRequestHeaders.Add("X-Auth-Email", config["cfEmail"]);
cfClient.DefaultRequestHeaders.Add("X-Auth-Key", config["cfKey"]); cfClient.DefaultRequestHeaders.Add("X-Auth-Key", config["cfKey"]);
@@ -141,8 +152,9 @@ static async Task UpdateDnsIpAsync(IConfiguration config, AAAARecord record, str
await UpdateDnsIpAsync(config, record, ip); await UpdateDnsIpAsync(config, record, ip);
} }
}
record AAAARecord(string comment, string content, string name, string id);
record RecordList(List<AAAARecord> result);
} }
record AAAARecord(string comment, string content, string name, string id);
record RecordList(List<AAAARecord> result);