11import Cors from "cors" ;
22import initMiddleware from "./init-middleware" ;
3+ import type { NextApiResponse } from "next" ;
34
45const rawOrigins = process . env . CORS_ORIGINS || "" ;
56const allowedOrigins =
@@ -10,6 +11,8 @@ export const cors = initMiddleware(
1011 methods : [ "GET" , "POST" , "OPTIONS" ] ,
1112 allowedHeaders : [ "Content-Type" , "Authorization" ] ,
1213 credentials : true ,
14+ optionsSuccessStatus : 200 , // Some legacy browsers choke on 204
15+ preflightContinue : false ,
1316 origin : function (
1417 origin : string | undefined ,
1518 callback : ( err : Error | null , allow ?: boolean ) => void ,
@@ -55,3 +58,11 @@ export const cors = initMiddleware(
5558 } ,
5659 } ) ,
5760) ;
61+
62+ // Helper function to add cache-busting headers for CORS
63+ export function addCorsCacheBustingHeaders ( res : NextApiResponse ) {
64+ res . setHeader ( 'Cache-Control' , 'no-cache, no-store, must-revalidate' ) ;
65+ res . setHeader ( 'Pragma' , 'no-cache' ) ;
66+ res . setHeader ( 'Expires' , '0' ) ;
67+ res . setHeader ( 'Vary' , 'Origin' ) ;
68+ }
0 commit comments