Skip to content

Commit 77ab72c

Browse files
committed
Bump web to .NET 8.0 and update all dependencies
1 parent ff23d9e commit 77ab72c

File tree

4 files changed

+156
-202
lines changed

4 files changed

+156
-202
lines changed

src/DnsTools.Web/DnsTools.Web.csproj

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
66
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
77
<IsPackable>false</IsPackable>
@@ -15,22 +15,25 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="AspNetCore.HealthChecks.Prometheus.Metrics" Version="6.0.2" />
19-
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="6.0.4" />
20-
<PackageReference Include="DnsClient" Version="1.6.1" />
21-
<PackageReference Include="GitInfo" Version="2.2.0" />
22-
<PackageReference Include="IPinfo" Version="2.0.0" />
23-
<PackageReference Include="MaxMind.GeoIP2" Version="5.1.0" />
24-
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="6.0.6" />
25-
<PackageReference Include="Google.Protobuf" Version="3.25.2" />
26-
<PackageReference Include="Grpc.Net.Client" Version="2.60.0" />
27-
<PackageReference Include="Grpc.Tools" Version="2.60.0">
18+
<PackageReference Include="AspNetCore.HealthChecks.Prometheus.Metrics" Version="8.0.1" />
19+
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="8.0.1" />
20+
<PackageReference Include="DnsClient" Version="1.7.0" />
21+
<PackageReference Include="GitInfo" Version="3.3.4">
2822
<PrivateAssets>all</PrivateAssets>
2923
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3024
</PackageReference>
31-
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
32-
<PackageReference Include="Reinforced.Typings" Version="1.6.1" />
33-
<PackageReference Include="Sentry.AspNetCore" Version="3.41.1" />
25+
<PackageReference Include="IPinfo" Version="3.0.0" />
26+
<PackageReference Include="MaxMind.GeoIP2" Version="5.2.0" />
27+
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="8.0.4" />
28+
<PackageReference Include="Google.Protobuf" Version="3.26.1" />
29+
<PackageReference Include="Grpc.Net.Client" Version="2.62.0" />
30+
<PackageReference Include="Grpc.Tools" Version="2.63.0">
31+
<PrivateAssets>all</PrivateAssets>
32+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
33+
</PackageReference>
34+
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
35+
<PackageReference Include="Reinforced.Typings" Version="1.6.3" />
36+
<PackageReference Include="Sentry.AspNetCore" Version="4.6.0" />
3437
</ItemGroup>
3538

3639
<ItemGroup>

src/DnsTools.Web/Program.cs

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/DnsTools.Web/Startup.cs

Lines changed: 138 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Net;
34
using DnsClient;
45
using DnsTools.Web.HealthChecks;
56
using DnsTools.Web.Hubs;
@@ -18,147 +19,144 @@
1819
using Microsoft.Extensions.Diagnostics.HealthChecks;
1920
using Microsoft.Extensions.Hosting;
2021

21-
namespace DnsTools.Web
22+
const string CORS_PROD = "prod";
23+
const string CORS_DEV = "dev";
24+
25+
var builder = WebApplication.CreateBuilder(args);
26+
27+
builder.WebHost
28+
.UseSentry(options =>
29+
{
30+
options.Release = ThisAssembly.Git.Sha;
31+
});
32+
33+
var config = builder.Configuration;
34+
// Config shared between client-side and server-side
35+
config.AddJsonFile("ClientApp/src/config.json");
36+
37+
var services = builder.Services;
38+
// Default caching DNS client, eg. for reverse DNS lookups
39+
services.AddSingleton<ILookupClient>(_ => new LookupClient(new LookupClientOptions
40+
{
41+
UseCache = true
42+
}));
43+
44+
services.Configure<AppConfig>(config);
45+
services.AddSentryTunneling("errors.d.sb");
46+
services.AddSingleton<IHttp2PushManifestHandler, Http2PushManifestHandler>();
47+
services.AddSingleton<IWorkerProvider, WorkerProvider>();
48+
services.AddSingleton<IIpDataProvider, IpDataProvider>();
49+
services.AddScoped<ICaptcha, Captcha>();
50+
51+
services.AddSingleton<IIpDataLoader, IpInfoIpDataLoader>();
52+
services.AddSingleton<IIpDataLoader, MaxMindIpDataLoader>();
53+
54+
services.AddSingleton<TracerouteRunner>();
55+
services.AddTransient<MtrRunner>();
56+
57+
services.AddHttpClient();
58+
services.AddHttpContextAccessor();
59+
60+
services.AddCors(options =>
61+
{
62+
options.AddPolicy(CORS_PROD , builder =>
63+
{
64+
builder.WithOrigins("https://dnstools.ws", "https://staging.dnstools.ws")
65+
.AllowAnyHeader()
66+
.AllowCredentials();
67+
});
68+
69+
options.AddPolicy(CORS_DEV, builder =>
70+
{
71+
builder.WithOrigins(
72+
// create-react-app server
73+
"http://localhost:64329",
74+
// react-snap server
75+
"http://localhost:45678"
76+
)
77+
.AllowAnyHeader()
78+
.AllowCredentials();
79+
});
80+
});
81+
82+
services.AddControllersWithViews();
83+
services.AddSignalR().AddJsonProtocol(options =>
84+
{
85+
options.PayloadSerializerOptions.IgnoreNullValues = true;
86+
});
87+
88+
services.AddDistributedMemoryCache();
89+
services.AddSession(options =>
90+
{
91+
options.IdleTimeout = TimeSpan.FromHours(1);
92+
options.Cookie.HttpOnly = true;
93+
options.Cookie.IsEssential = true;
94+
options.Cookie.Name = ".DnsTools.Session";
95+
options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
96+
});
97+
98+
ConfigureHealthChecks(services.AddHealthChecks());
99+
100+
var app = builder.Build();
101+
102+
if (app.Environment.IsDevelopment())
103+
{
104+
app.UseDeveloperExceptionPage();
105+
// Allow unencrypted gRPC calls in development
106+
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
107+
}
108+
else
109+
{
110+
app.UseExceptionHandler("/Error/Error");
111+
app.UseStatusCodePagesWithReExecute("/Error/Status{0}");
112+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
113+
app.UseHsts();
114+
}
115+
116+
app.UseHttpsRedirection();
117+
app.UseForwardedHeaders(new ForwardedHeadersOptions
118+
{
119+
ForwardedHeaders = ForwardedHeaders.XForwardedFor
120+
});
121+
app.UseStaticFiles();
122+
app.UseSession();
123+
124+
app.UseRouting();
125+
app.UseCors(app.Environment.IsDevelopment() ? CORS_DEV : CORS_PROD);
126+
app.UseSentryTunneling("/error/log");
127+
128+
app.UseHealthChecksPrometheusExporter("/health/prom", options =>
129+
{
130+
options.ResultStatusCodes = new Dictionary<HealthStatus, int>
131+
{
132+
// Always return HTTP 200 so Prometheus sees the request as successful.
133+
{HealthStatus.Healthy, 200},
134+
{HealthStatus.Degraded, 200},
135+
{HealthStatus.Unhealthy, 200},
136+
};
137+
});
138+
139+
app.MapHealthChecks("/health");
140+
app.MapHealthChecks("/health/json", new HealthCheckOptions
141+
{
142+
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse,
143+
});
144+
145+
app.MapHub<ToolsHub>("/hub");
146+
app.MapControllerRoute(
147+
name: "default",
148+
pattern: "{controller}/{action=Index}/{id?}"
149+
);
150+
151+
app.Run();
152+
153+
return;
154+
155+
void ConfigureHealthChecks(IHealthChecksBuilder builder)
22156
{
23-
public class Startup
157+
var appConfig = config.Get<AppConfig>();
158+
foreach (var worker in appConfig.Workers)
24159
{
25-
private const string CORS_PROD = "prod";
26-
private const string CORS_DEV = "dev";
27-
28-
public Startup(IConfiguration configuration)
29-
{
30-
Configuration = configuration;
31-
}
32-
33-
public IConfiguration Configuration { get; }
34-
35-
// This method gets called by the runtime. Use this method to add services to the container.
36-
public void ConfigureServices(IServiceCollection services)
37-
{
38-
// Default caching DNS client, eg. for reverse DNS lookups
39-
services.AddSingleton<ILookupClient>(_ => new LookupClient(new LookupClientOptions
40-
{
41-
UseCache = true
42-
}));
43-
44-
services.Configure<AppConfig>(Configuration);
45-
services.AddSentryTunneling("errors.d.sb");
46-
services.AddSingleton<IHttp2PushManifestHandler, Http2PushManifestHandler>();
47-
services.AddSingleton<IWorkerProvider, WorkerProvider>();
48-
services.AddSingleton<IIpDataProvider, IpDataProvider>();
49-
services.AddScoped<ICaptcha, Captcha>();
50-
51-
services.AddSingleton<IIpDataLoader, IpInfoIpDataLoader>();
52-
services.AddSingleton<IIpDataLoader, MaxMindIpDataLoader>();
53-
54-
services.AddSingleton<TracerouteRunner>();
55-
services.AddTransient<MtrRunner>();
56-
57-
services.AddHttpClient();
58-
services.AddHttpContextAccessor();
59-
60-
services.AddCors(options =>
61-
{
62-
options.AddPolicy(CORS_PROD , builder =>
63-
{
64-
builder.WithOrigins("https://dnstools.ws")
65-
.AllowAnyHeader()
66-
.AllowCredentials();
67-
});
68-
69-
options.AddPolicy(CORS_DEV, builder =>
70-
{
71-
builder.WithOrigins(
72-
// create-react-app server
73-
"http://localhost:31429",
74-
// react-snap server
75-
"http://localhost:45678"
76-
)
77-
.AllowAnyHeader()
78-
.AllowCredentials();
79-
});
80-
});
81-
82-
services.AddControllersWithViews();
83-
services.AddSignalR().AddJsonProtocol(options =>
84-
{
85-
options.PayloadSerializerOptions.IgnoreNullValues = true;
86-
});
87-
88-
services.AddDistributedMemoryCache();
89-
services.AddSession(options =>
90-
{
91-
options.IdleTimeout = TimeSpan.FromHours(1);
92-
options.Cookie.HttpOnly = true;
93-
options.Cookie.IsEssential = true;
94-
options.Cookie.Name = ".DnsTools.Session";
95-
options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
96-
});
97-
98-
ConfigureHealthChecks(services.AddHealthChecks());
99-
}
100-
101-
private void ConfigureHealthChecks(IHealthChecksBuilder builder)
102-
{
103-
var config = Configuration.Get<AppConfig>();
104-
foreach (var worker in config.Workers)
105-
{
106-
builder.AddTypeActivatedCheck<WorkerHealthCheck>($"worker_{worker.Id}", worker.Id);
107-
}
108-
}
109-
110-
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
111-
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
112-
{
113-
if (env.IsDevelopment())
114-
{
115-
app.UseDeveloperExceptionPage();
116-
// Allow unencrypted gRPC calls in development
117-
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
118-
}
119-
else
120-
{
121-
app.UseExceptionHandler("/Error/Error");
122-
app.UseStatusCodePagesWithReExecute("/Error/Status{0}");
123-
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
124-
app.UseHsts();
125-
}
126-
127-
app.UseHttpsRedirection();
128-
app.UseForwardedHeaders(new ForwardedHeadersOptions
129-
{
130-
ForwardedHeaders = ForwardedHeaders.XForwardedFor
131-
});
132-
app.UseStaticFiles();
133-
app.UseSession();
134-
135-
app.UseRouting();
136-
app.UseCors(env.IsDevelopment() ? CORS_DEV : CORS_PROD);
137-
app.UseSentryTunneling("/error/log");
138-
139-
app.UseHealthChecksPrometheusExporter("/health/prom", options =>
140-
{
141-
options.ResultStatusCodes = new Dictionary<HealthStatus, int>
142-
{
143-
// Always return HTTP 200 so Prometheus sees the request as successful.
144-
{HealthStatus.Healthy, 200},
145-
{HealthStatus.Degraded, 200},
146-
{HealthStatus.Unhealthy, 200},
147-
};
148-
});
149-
app.UseEndpoints(endpoints =>
150-
{
151-
endpoints.MapHealthChecks("/health");
152-
endpoints.MapHealthChecks("/health/json", new HealthCheckOptions
153-
{
154-
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse,
155-
});
156-
157-
endpoints.MapHub<ToolsHub>("/hub");
158-
endpoints.MapControllerRoute(
159-
name: "default",
160-
pattern: "{controller}/{action=Index}/{id?}");
161-
});
162-
}
160+
builder.AddTypeActivatedCheck<WorkerHealthCheck>($"worker_{worker.Id}", worker.Id);
163161
}
164162
}

src/DnsTools.Web/publish.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ switch ($choice) {
2828
2 { $remoteDir = "dnstools" }
2929
}
3030

31-
wsl.exe rsync -av --progress ./bin/Release/net6.0/linux-x64/publish/ daniel@d.sb:/var/www/$remoteDir/
31+
wsl.exe rsync -av --progress ./bin/Release/net8.0/linux-x64/publish/ daniel@d.sb:/var/www/$remoteDir/

0 commit comments

Comments
 (0)