From 226a64df417bdb3a0642c18a7dac499f91123bc1 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 21 Nov 2025 01:21:40 +0800 Subject: [PATCH] :lipstick: Optimize the page rendering in zone --- DysonNetwork.Zone/Caddyfile | 5 +++ DysonNetwork.Zone/Pages/Index.cshtml | 12 ++++-- DysonNetwork.Zone/Pages/Index.cshtml.cs | 50 +++++++++++++++++++++++-- DysonNetwork.Zone/Program.cs | 5 +-- 4 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 DysonNetwork.Zone/Caddyfile diff --git a/DysonNetwork.Zone/Caddyfile b/DysonNetwork.Zone/Caddyfile new file mode 100644 index 0000000..233cecc --- /dev/null +++ b/DysonNetwork.Zone/Caddyfile @@ -0,0 +1,5 @@ +http://localhost:3001 { + reverse_proxy localhost:8007 { + header_up X-SiteName "ciallo" + } +} diff --git a/DysonNetwork.Zone/Pages/Index.cshtml b/DysonNetwork.Zone/Pages/Index.cshtml index bcf108a..b3123cc 100644 --- a/DysonNetwork.Zone/Pages/Index.cshtml +++ b/DysonNetwork.Zone/Pages/Index.cshtml @@ -2,14 +2,18 @@ @model IndexModel @{ ViewData["Title"] = "Solar Network Pages"; - ViewData["SiteName"] = Request.Headers.TryGetValue("X-SiteName", out var val) ? val : "main"; + ViewData["SiteName"] = Model.SiteName ?? "main"; }
-
- Logo +
+ Logo

Hello, World 👋

-

Here are the Solar Network Pages construction site

+

Here are the Solar Network Pages

And you're accessing the site @ViewData["SiteName"]

+

+ The reason you're seeing this is the author of the site + haven't configure anything that match this route. +

diff --git a/DysonNetwork.Zone/Pages/Index.cshtml.cs b/DysonNetwork.Zone/Pages/Index.cshtml.cs index c3ee761..83fee41 100644 --- a/DysonNetwork.Zone/Pages/Index.cshtml.cs +++ b/DysonNetwork.Zone/Pages/Index.cshtml.cs @@ -1,11 +1,55 @@ +using DysonNetwork.Shared.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; namespace DysonNetwork.Zone.Pages; -public class IndexModel : PageModel +public class IndexModel(AppDatabase db) : PageModel { - public void OnGet() + public string? SiteName { get; set; } + + public async Task OnGet(string? path = null) { + var siteNameValue = Request.Headers["X-SiteName"].ToString(); + SiteName = siteNameValue; + if (string.IsNullOrEmpty(siteNameValue)) + { + SiteName = null; + } + else + { + var capturedName = siteNameValue; + var site = await db.PublicationSites.FirstOrDefaultAsync(s => + s.Name == capturedName && s.Mode == PublicationSiteMode.FullyManaged); + if (site != null) + { + var pagePath = "/" + (path ?? ""); + if (pagePath == "/") pagePath = "/"; + + var page = await db.PublicationPages.FirstOrDefaultAsync(p => + p.SiteId == site.Id && p.Path == pagePath); + if (page != null) + { + if (page.Type == PublicationPageType.HtmlPage) + { + if (page.Config.TryGetValue("html", out var html) && html is string content) + { + return Content(content, "text/html"); + } + } + else if (page.Type == PublicationPageType.Redirect) + { + if (page.Config.TryGetValue("url", out var url) && url is string redirectUrl) + { + return Redirect(redirectUrl); + } + } + } + } + } + + return Page(); } -} \ No newline at end of file +} + diff --git a/DysonNetwork.Zone/Program.cs b/DysonNetwork.Zone/Program.cs index 717e2a5..b227cd1 100644 --- a/DysonNetwork.Zone/Program.cs +++ b/DysonNetwork.Zone/Program.cs @@ -11,8 +11,7 @@ builder.AddServiceDefaults(); builder.ConfigureAppKestrel(builder.Configuration); -// Add services to the container. -builder.Services.AddRazorPages(); +builder.Services.AddRazorPages(options => options.Conventions.AddPageRoute("/Index", "{**path}")); builder.Services.AddControllers(); builder.Services.AddAppServices(); @@ -54,4 +53,4 @@ app.MapRazorPages(); app.UseSwaggerManifest("DysonNetwork.Zone"); -app.Run(); \ No newline at end of file +app.Run();