💄 Optimize the page rendering in zone

This commit is contained in:
2025-11-21 01:21:40 +08:00
parent 75b8567a28
commit 226a64df41
4 changed files with 62 additions and 10 deletions

View File

@@ -0,0 +1,5 @@
http://localhost:3001 {
reverse_proxy localhost:8007 {
header_up X-SiteName "ciallo"
}
}

View File

@@ -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";
}
<div class="h-screen flex justify-center items-center">
<div class="text-center">
<img src="~/favicon.png" width="80" height="80" alt="Logo" class="mb-1 mx-auto" />
<div class="text-center max-w-96">
<img src="~/favicon.png" width="80" height="80" alt="Logo" class="mb-1 mx-auto"/>
<h1 class="text-2xl">Hello, World 👋</h1>
<p>Here are the Solar Network Pages construction site</p>
<p>Here are the Solar Network Pages</p>
<p>And you're accessing the site <b>@ViewData["SiteName"]</b></p>
<p class="text-sm opacity-80 mt-1">
The reason you're seeing this is the author of the site
haven't configure anything that match this route.
</p>
</div>
</div>

View File

@@ -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<IActionResult> 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();
}
}

View File

@@ -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();