🧱 Mixed page infra

This commit is contained in:
2025-07-16 13:00:10 +08:00
parent cd4af2e26f
commit e4dcf2517a
10 changed files with 95 additions and 12 deletions

View File

@@ -1,13 +1,14 @@
<!DOCTYPE html>
<html lang="">
<head>
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Solarpass</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
%%APP_DATA%%
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

View File

@@ -9,10 +9,11 @@
<p class="mt-4 opacity-75 text-xs">
<span v-if="version == null">Loading...</span>
<span v-else
>v{{ version.version }} @ {{ version.commit.substring(0, 6) }}
{{ version.updatedAt }}</span
>
<span v-else>
v{{ version.version }} @
{{ version.commit.substring(0, 6) }}
{{ version.updatedAt }}
</span>
</p>
</n-card>
</section>

View File

@@ -0,0 +1,24 @@
using DysonNetwork.Shared.Data;
using DysonNetwork.Shared.PageData;
namespace DysonNetwork.Pass.Pages.Data;
public class VersionPageData : IPageDataProvider
{
public bool CanHandlePath(PathString path) => true;
public Task<IDictionary<string, object?>> GetAppDataAsync(HttpContext context)
{
var versionData = new AppVersion
{
Version = ThisAssembly.AssemblyVersion,
Commit = ThisAssembly.GitCommitId,
UpdateDate = ThisAssembly.GitCommitDate
};
var result = typeof(AppVersion).GetProperties()
.ToDictionary(property => property.Name, property => property.GetValue(versionData));
return Task.FromResult<IDictionary<string, object?>>(result);
}
}

View File

@@ -1,6 +1,9 @@
using System.Text.Json;
using DysonNetwork.Pass;
using DysonNetwork.Pass.Pages.Data;
using DysonNetwork.Pass.Startup;
using DysonNetwork.Shared.Http;
using DysonNetwork.Shared.PageData;
using DysonNetwork.Shared.Registry;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.FileProviders;
@@ -30,6 +33,8 @@ builder.Services.AddAppBusinessServices(builder.Configuration);
// Add scheduled jobs
builder.Services.AddAppScheduledJobs();
builder.Services.AddTransient<IPageDataProvider, VersionPageData>();
var app = builder.Build();
// Run database migrations
@@ -42,6 +47,8 @@ using (var scope = app.Services.CreateScope())
// Configure application middleware pipeline
app.ConfigureAppMiddleware(builder.Configuration, builder.Environment.ContentRootPath);
app.MapPages(Path.Combine(builder.Environment.WebRootPath, "dist", "index.html"));
// Configure gRPC
app.ConfigureGrpcServices();

View File

@@ -46,8 +46,6 @@ public static class ApplicationConfiguration
app.MapControllers().RequireRateLimiting("fixed");
app.MapFallbackToFile("dist/index.html");
return app;
}

View File

@@ -0,0 +1,9 @@
using Microsoft.AspNetCore.Http;
namespace DysonNetwork.Shared.PageData;
public interface IPageDataProvider
{
bool CanHandlePath(PathString path);
Task<IDictionary<string, object?>> GetAppDataAsync(HttpContext context);
}

View File

@@ -0,0 +1,42 @@
using System.Text.Json;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
namespace DysonNetwork.Shared.PageData;
public static class PageStartup
{
public static WebApplication MapPages(this WebApplication app, string defaultFile)
{
#pragma warning disable ASP0016
app.MapFallback(async context =>
{
var html = await File.ReadAllTextAsync(defaultFile);
using var scope = app.Services.CreateScope();
var providers = scope.ServiceProvider.GetServices<IPageDataProvider>();
var matches = providers
.Where(p => p.CanHandlePath(context.Request.Path))
.Select(p => p.GetAppDataAsync(context))
.ToList();
var results = await Task.WhenAll(matches);
var appData = new Dictionary<string, object?>();
foreach (var result in results)
foreach (var (key, value) in result)
appData[key] = value;
var json = JsonSerializer.Serialize(appData);
html = html.Replace("%%APP_DATA%%", $"<script>window.__APP_DATA__ = {json};</script>");
context.Response.ContentType = "text/html";
await context.Response.WriteAsync(html);
});
#pragma warning restore ASP0016
return app;
}
}

View File

@@ -43,6 +43,7 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExceptionDispatchInfo_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb6f0571a6bc744b0b551fd4578292582e54c00_003Fbf_003F44af6d95_003FExceptionDispatchInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExifTag_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa932cb9090ed48088111ae919dcdd9021ba00_003Fd7_003F0472c800_003FExifTag_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExifTag_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fef3339e864a448e2b1ec6fa7bbf4c6661fee00_003F5c_003F8ed75f18_003FExifTag_002Ecs_002Fz_003A2_002D1/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFallbackEndpointRouteBuilderExtensions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F6f0e72efb51e41ccadc2866f234ce618e5400_003F6e_003F2107b0b6_003FFallbackEndpointRouteBuilderExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFieldMask_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F331aca3f6f414013b09964063341351379060_003F68_003Fc6da3cbf_003FFieldMask_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFileResult_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F0b5acdd962e549369896cece0026e556214600_003F8c_003F9f6e3f4f_003FFileResult_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AForwardedHeaders_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fcfe5737f9bb84738979cbfedd11822a8ea00_003F50_003F9a335f87_003FForwardedHeaders_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>