💄 Optimize the page rendering in zone
This commit is contained in:
5
DysonNetwork.Zone/Caddyfile
Normal file
5
DysonNetwork.Zone/Caddyfile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
http://localhost:3001 {
|
||||||
|
reverse_proxy localhost:8007 {
|
||||||
|
header_up X-SiteName "ciallo"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,14 +2,18 @@
|
|||||||
@model IndexModel
|
@model IndexModel
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Solar Network Pages";
|
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="h-screen flex justify-center items-center">
|
||||||
<div class="text-center">
|
<div class="text-center max-w-96">
|
||||||
<img src="~/favicon.png" width="80" height="80" alt="Logo" class="mb-1 mx-auto" />
|
<img src="~/favicon.png" width="80" height="80" alt="Logo" class="mb-1 mx-auto"/>
|
||||||
<h1 class="text-2xl">Hello, World 👋</h1>
|
<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>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>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,11 +1,55 @@
|
|||||||
|
using DysonNetwork.Shared.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace DysonNetwork.Zone.Pages;
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ builder.AddServiceDefaults();
|
|||||||
|
|
||||||
builder.ConfigureAppKestrel(builder.Configuration);
|
builder.ConfigureAppKestrel(builder.Configuration);
|
||||||
|
|
||||||
// Add services to the container.
|
builder.Services.AddRazorPages(options => options.Conventions.AddPageRoute("/Index", "{**path}"));
|
||||||
builder.Services.AddRazorPages();
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
builder.Services.AddAppServices();
|
builder.Services.AddAppServices();
|
||||||
@@ -54,4 +53,4 @@ app.MapRazorPages();
|
|||||||
|
|
||||||
app.UseSwaggerManifest("DysonNetwork.Zone");
|
app.UseSwaggerManifest("DysonNetwork.Zone");
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|||||||
Reference in New Issue
Block a user