Initial commit

This commit is contained in:
pigui
2026-08-30 21:11:59 +02:00
commit 3f930bb46a
168 changed files with 35708 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import { defineEventHandler, getRequestURL, setResponseStatus } from 'h3';
/**
* Answers 404 for addresses this app does not serve.
*
* The status cannot be set from the catch-all page's `load`: Analog resolves
* loaders through an internal request, so anything set on that response never
* reaches the browser. Here it can be, and the route table is small enough to
* state outright — the landing is one page.
*/
const KNOWN_PATHS = new Set(['/', '/index.html']);
const PASSTHROUGH_PREFIXES = ['/api/', '/_analog/', '/assets/', '/@', '/src/', '/node_modules/'];
export default defineEventHandler((event) => {
const { pathname } = getRequestURL(event);
if (KNOWN_PATHS.has(pathname)) {
return;
}
// Static files answer for themselves — a missing one is Nitro's 404, not a
// page, and stamping this status on a hit would break the asset.
if (
PASSTHROUGH_PREFIXES.some((prefix) => pathname.startsWith(prefix)) ||
/\.[a-z0-9]+$/i.test(pathname)
) {
return;
}
setResponseStatus(event, 404);
});