11import type { FastifyInstance } from "fastify" ;
2- import type { ParsedConfig } from "../../schema/config " ;
2+ import { getConfig } from "../../utils/cache/getConfig " ;
33import { ADMIN_QUEUES_BASEPATH } from "./adminRoutes" ;
44
55const STANDARD_METHODS = "GET,POST,DELETE,PUT,PATCH,HEAD,PUT,PATCH,POST,DELETE" ;
@@ -9,7 +9,7 @@ const DEFAULT_ALLOWED_HEADERS = [
99 "ngrok-skip-browser-warning" ,
1010] ;
1111
12- export function withCors ( server : FastifyInstance , config : ParsedConfig ) {
12+ export function withCors ( server : FastifyInstance ) {
1313 server . addHook ( "onRequest" , async ( request , reply ) => {
1414 const origin = request . headers . origin ;
1515
@@ -29,13 +29,20 @@ export function withCors(server: FastifyInstance, config: ParsedConfig) {
2929 return ;
3030 }
3131
32+ const config = await getConfig ( ) ;
3233 const allowedOrigins = config . accessControlAllowOrigin
3334 . split ( "," )
3435 . map ( sanitizeOrigin ) ;
3536
3637 // Always set `Vary: Origin` to prevent caching issues even on invalid origins.
3738 reply . header ( "Vary" , "Origin" ) ;
3839
40+ console . log ( "[DEBUG] allowedOrigins:" , allowedOrigins ) ;
41+ console . log (
42+ "[DEBUG] isAllowedOrigin(origin, allowedOrigins):" ,
43+ isAllowedOrigin ( origin , allowedOrigins ) ,
44+ ) ;
45+
3946 if ( isAllowedOrigin ( origin , allowedOrigins ) ) {
4047 // Set CORS headers if valid origin.
4148 reply . header ( "Access-Control-Allow-Origin" , origin ) ;
@@ -56,7 +63,7 @@ export function withCors(server: FastifyInstance, config: ParsedConfig) {
5663 return ;
5764 }
5865 } else {
59- reply . code ( 403 ) . send ( { error : "Invalid origin" } ) ;
66+ // reply.code(403).send({ error: "Invalid origin" });
6067 return ;
6168 }
6269 } ) ;
0 commit comments