Cors Update

This commit is contained in:
Rokojori 2026-07-15 17:31:27 +02:00
parent c9932b80a7
commit 36ee71a7c9
1 changed files with 18 additions and 0 deletions

View File

@ -12,6 +12,24 @@ app.set( 'trust proxy', 1 );
app.use( express.json() );
app.use( cookieParser() );
// CORS for public font resources — only allowed origins receive the header
const CORS_ALLOWED: Array<string | RegExp> = [
/^https?:\/\/([\w-]+\.)?rokojori\.com$/,
];
function allowFontCors( req: express.Request, res: express.Response, next: express.NextFunction ): void
{
const origin = req.headers.origin;
if ( origin && CORS_ALLOWED.some( rule => typeof rule === 'string' ? rule === origin : rule.test( origin ) ) )
{
res.set( 'Access-Control-Allow-Origin', origin );
}
next();
}
app.use( '/get-font', allowFontCors );
app.use( '/fonts', allowFontCors );
// Public: font CSS endpoint
app.use( publicFontsRouter );