File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,18 +33,20 @@ export async function corsMiddleware(c: Context<{ Bindings: Env }>, next: () =>
3333 // Not allowed origin: log details for troubleshooting
3434 try {
3535 const url = new URL ( c . req . url ) ;
36- console . warn ( '[CORS] Blocked request ' , {
36+ console . warn ( '[CORS_BLOCK] ' , JSON . stringify ( {
3737 method : c . req . method ,
3838 path : url . pathname ,
3939 origin,
4040 allowedOrigins,
41- } ) ;
41+ timestamp : new Date ( ) . toISOString ( ) ,
42+ } ) ) ;
4243 } catch ( _ ) {
43- console . warn ( '[CORS] Blocked request ' , {
44+ console . warn ( '[CORS_BLOCK] ' , JSON . stringify ( {
4445 method : c . req . method ,
4546 origin,
4647 allowedOrigins,
47- } ) ;
48+ timestamp : new Date ( ) . toISOString ( ) ,
49+ } ) ) ;
4850 }
4951 if ( c . req . method === 'OPTIONS' ) {
5052 return c . text ( 'Forbidden' , 403 ) ;
@@ -63,7 +65,8 @@ export async function corsMiddleware(c: Context<{ Bindings: Env }>, next: () =>
6365 c . header ( 'Access-Control-Max-Age' , '86400' ) ;
6466
6567 if ( c . req . method === 'OPTIONS' ) {
66- return new Response ( null , { status : 204 } ) ;
68+ // Hono のコンテキスト経由で返すことで設定したヘッダーを維持
69+ return c . body ( null , 204 ) ;
6770 }
6871
6972 await next ( ) ;
You can’t perform that action at this time.
0 commit comments