Adds a preview server that follows the real server rules

Lighthouse and the browser tests need a real 404 status, the .html mapping and
the production headers, which vite preview does not give. It is not wired into
the scripts yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 18:20:22 +01:00
co-authored by Claude Opus 5.5
parent 2c2e27e337
commit 0b964b5466
5 changed files with 863 additions and 19 deletions
+86
View File
@@ -0,0 +1,86 @@
import fc from 'fast-check';
import { pathSegment } from './arbitraries';
// Generatoren voor verzoekpaden van de preview-server (BR-SRV). Los van
// arbitraries.ts, zodat die klein blijft (PBT-07).
// Stukken die een pad onveilig of vreemd maken: puntsegmenten in elke
// codering, NUL, backslashes, kapotte en dubbele codering, unicode
export const hostileFragment = fc.constantFrom(
'..',
'.',
'...',
'.. ',
'%2e%2e',
'%2E%2E',
'%2e',
'%252e%252e',
'..%2f',
'%2f..',
'%5c',
'\\',
'..\\',
'%00',
'\0',
'%',
'%zz',
'%c0%af',
'%ff',
'',
'c:',
'日本語',
'é',
'\u{1F600}',
' ',
);
const anySegment = fc.oneof(
{ weight: 3, arbitrary: pathSegment },
{ weight: 3, arbitrary: hostileFragment },
{ weight: 1, arbitrary: fc.string({ unit: 'binary', maxLength: 6 }) },
);
// Een pad zoals een client het kan sturen: meestal met voorste slash, soms
// zonder, soms rauwe tekst
export const anyRequestPath = fc.oneof(
{
weight: 5,
arbitrary: fc
.tuple(fc.boolean(), fc.array(anySegment, { maxLength: 5 }))
.map(
([leading, segments]) =>
(leading ? '/' : '') + segments.join('/'),
),
},
{ weight: 1, arbitrary: fc.string({ unit: 'binary', maxLength: 20 }) },
);
// Een bestandsnaam met extensie, zoals een verzoek om een asset
export const dottedFileName = fc.stringMatching(
/^[a-z0-9-]{1,10}\.[a-z0-9]{1,5}$/,
);
// Een naam zonder punt, voor een paginaverzoek als /x
export const pageName = fc.stringMatching(/^[a-z0-9-]{1,12}$/);
const directory = fc.array(pathSegment, { maxLength: 2 });
// Een bestand in clientDir: een paginabestand of een bestand met punt in een map
const existingFile = fc.oneof(
fc
.tuple(directory, pageName)
.map(([dirs, name]) => [...dirs, `${name}.html`].join('/')),
fc
.tuple(directory, dottedFileName)
.map(([dirs, name]) => [...dirs, name].join('/')),
);
// De bestanden die op schijf staan, als verzameling (het model van P17)
export const existingFiles = fc
.uniqueArray(existingFile, { maxLength: 12 })
.map((files) => new Set(files));
export const existsIn =
(files: ReadonlySet<string>) =>
(file: string): boolean =>
files.has(file);