Adds the URL rules to the preview server, IIS config and deploy

The preview server and web.config now follow the same URLs as nginx, without
the SPA fallback. Lighthouse exceptions need a recorded reason and the 404 page
is audited through an opt-in route. The deploy checks the build first and the
served result afterwards. The IIS rules stay unverified until a host exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-01 18:13:21 +01:00
co-authored by Claude Opus 5.5
parent 716692825e
commit e4e7f8c82c
17 changed files with 1919 additions and 220 deletions
+63 -12
View File
@@ -3,8 +3,8 @@
// dev- en preview-server. Zo bestaat de headerset maar op één plek.
// Schrijven: `pnpm server-config`. Een test controleert dat de bestanden in
// deploy/ gelijk zijn aan wat deze functies opleveren.
import { gzipMimeTypes } from './compressibleTypes.ts';
import { redirectNames, variantPattern } from './canonicalUrls.ts';
import { compressibleTypes, gzipMimeTypes } from './compressibleTypes.ts';
import { escapeRegex, redirectNames, variantPattern } from './canonicalUrls.ts';
import { securityHeaders } from './securityHeaders.ts';
const generatedNotice =
@@ -21,11 +21,17 @@ const xmlAttribute = (value: string) =>
// op deze hostname) en zoekmachines één adres zien
export const productionHost = 'andreaslop.nl';
// IIS (productie): www-doorverwijzing, security headers, HTTPS-redirect,
// SPA-fallback en caching. De www-regel staat vóór HTTPS, zodat
// http://www. in één stap op https://andreaslop.nl uitkomt.
// IIS (productie): www-doorverwijzing, security headers, HTTPS-redirect, de
// URL-regels uit de paginalijst (BR-HST-01 tot 08), compressie en caching.
// De www-regel staat vóór HTTPS, zodat http://www. in één stap op
// https://andreaslop.nl uitkomt. Deze regels zijn nog op geen echte IIS-host
// geprobeerd: de open punten U1 tot U6 staan in infrastructure-design.md.
// Bestanden in /assets hebben een hash in de naam en mogen lang gecachet
// worden; index.html nooit, zodat een nieuwe release direct zichtbaar is.
// worden; de pagina's nooit, zodat een nieuwe release direct zichtbaar is.
// MIME-types die IIS standaard anders of niet kent, worden vastgezet op de
// waarden uit compressibleTypes.ts, zodat statische compressie ze oppakt.
const iisPinnedExtensions = ['.js', '.svg', '.json', '.xml'];
export function iisWebConfig(): string {
const headers = Object.entries(securityHeaders('production'))
.map(
@@ -33,6 +39,20 @@ export function iisWebConfig(): string {
` <add name="${name}" value="${xmlAttribute(value)}" />`,
)
.join('\n');
const mimePins = compressibleTypes
.filter((type) => iisPinnedExtensions.includes(type.extension))
.map(
(type) =>
` <remove fileExtension="${type.extension}" />\n` +
` <mimeMap fileExtension="${type.extension}" mimeType="${xmlAttribute(type.mimeTypes[0])}" />`,
)
.join('\n');
// Paginanamen zonder voorste slash. De canonieke vorm is kleine letters;
// alleen een afwijkende schrijfwijze (hoofdletters, .html, slashes) wordt
// doorverwezen, ToLower raakt dus nooit de hash-namen in /assets.
const pageNames = redirectNames
.map((path) => escapeRegex(path.replace(/^\//, '')))
.join('|');
return `<?xml version="1.0" encoding="utf-8"?>
<!-- ${generatedNotice} -->
@@ -54,16 +74,46 @@ export function iisWebConfig(): string {
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
<rule name="SPA fallback" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<rule name="Index naar root" stopProcessing="true">
<match url="^${variantPattern('/')}$" />
<action type="Redirect" url="/" redirectType="Permanent" />
</rule>
<rule name="Pagina canoniek" stopProcessing="true">
<match url="^(${xmlAttribute(pageNames)})(?:\\.html)?/*$" />
<conditions>
<add input="{R:0}" pattern="^(?:${xmlAttribute(pageNames)})$" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
<action type="Redirect" url="/{ToLower:{R:1}}" redirectType="Permanent" />
</rule>
<rule name="Slash weg" stopProcessing="true">
<match url="^([^/\\\\].*?)/+$" />
<action type="Redirect" url="/{R:1}" redirectType="Permanent" />
</rule>
<rule name="404 direct" stopProcessing="true">
<match url="^404(?:\\.html)?$" />
<action type="CustomResponse" statusCode="404" statusReason="Not Found" statusDescription="Not Found" />
</rule>
<rule name="Pagina bestand" stopProcessing="true">
<match url="^(.+)$" />
<conditions>
<add input="{REQUEST_FILENAME}.html" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="{R:1}.html" />
</rule>
<rule name="Map zonder pagina" stopProcessing="true">
<match url="^(.+)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" />
</conditions>
<action type="CustomResponse" statusCode="404" statusReason="Not Found" statusDescription="Not Found" />
</rule>
</rules>
</rewrite>
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" path="/404.html" responseMode="ExecuteURL" />
</httpErrors>
<urlCompression doStaticCompression="true" doDynamicCompression="false" />
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
@@ -73,6 +123,7 @@ ${headers}
<staticContent>
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff2" mimeType="font/woff2" />
${mimePins}
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>