Files
slp-modular-cms/aidlc-docs/features/andreaslop-site-hosting/inception/application-design/component-methods.md
T

73 lines
3.5 KiB
Markdown

# Component Methods - andreaslop-site-hosting
Signatures are indicative; business rules are detailed in U1 Functional Design.
## Core - hosting
```csharp
public enum WebsiteMode { SpaFallback = 0, PrerenderedPages = 1 }
public sealed class CmsHostOptions { public WebsiteMode WebsiteMode { get; init; } = WebsiteMode.SpaFallback; }
```
## C3a WebsitePathResolver
```csharp
public abstract record WebsiteResolution
{
public sealed record ServeFile(string RelativePath, bool IsNotFoundPage = false) : WebsiteResolution;
public sealed record Redirect(string Location) : WebsiteResolution; // always 301, relative Location
public sealed record NotFound : WebsiteResolution;
}
public static class WebsitePathResolver
{
// Total: never throws, never returns a path outside the website root.
// fileExists receives a relative, forward-slash, already-validated candidate ("over-mij.html").
public static WebsiteResolution Resolve(string? rawPath, string? queryString, Func<string, bool> fileExists);
public static bool IsReservedPath(string? rawPath); // /admin, /api/v1, /health (whole segments, case-insensitive)
}
```
## C3b/C3c Website serving
```csharp
public sealed class WebsiteOptions { public const string SectionName = "Website"; public bool NoIndex { get; set; } }
public static class PrerenderedSiteExtensions
{
public static IServiceCollection AddCmsWebsite(this IServiceCollection s, IConfiguration c); // options + validation + compression
public static WebApplication UseCmsPrerenderedSite(this WebApplication app); // compression (UseWhen), noindex, resolver middleware
}
public sealed class PrerenderedSiteMiddleware(RequestDelegate next, IWebHostEnvironment env, IOptions<WebsiteOptions> options)
{
public Task InvokeAsync(HttpContext context);
}
```
`StaticContentExtensions.UseCmsStaticContent` / `MapCmsSpaFallbacks` branch on `WebsiteMode`: in `PrerenderedPages` they register the admin mount and the `/admin` fallback only, the website mount is `UseCmsPrerenderedSite`, and the catch-all website fallback is replaced by the middleware's 404 handling placed after API routes.
## C4 Security
```csharp
public static class CspPolicyCatalog
{
public const string StrictSite = "StrictSite";
public static SecurityHeaderSet Build(string policy,
IEnumerable<string> allowedScriptOrigins, IEnumerable<string> allowedConnectOrigins,
IEnumerable<string>? siteScriptOrigins = null, IEnumerable<string>? siteConnectOrigins = null);
}
public sealed class SecurityHeadersOptions { /* + */ public IList<string> AllowedSiteScriptOrigins { get; set; } = []; public IList<string> AllowedSiteConnectOrigins { get; set; } = []; }
```
Existing call sites keep compiling (new parameters optional).
## C7 Setup token
```csharp
public sealed class SetupOptions { public const string SectionName = "Identity:Setup"; public string? Token { get; set; } }
public interface ISetupTokenValidator { bool IsRequired { get; } bool IsValid(string? presentedToken); } // fixed-time comparison
// SetupController
// GET /Setup/status -> { initialized, tokenRequired }
// POST /Setup/owner -> 401/403 problem details when token required and missing/wrong; header X-Setup-Token
```
## Frontend
- `theme.ts`/Vite plugin: resolves `VITE_THEME` to `themes/<name>/theme.css` import (no-op when unset).
- `i18n init`: `lng = stored ?? import.meta.env.VITE_DEFAULT_LANGUAGE ?? browser default`.
- Setup page: optional `setupToken` field; API client adds `X-Setup-Token` header.