File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { createResponse } from './utils';
22import handleStudioRequest from "./studio" ;
33import { Handler } from "./handler" ;
44import { DatabaseStub , DataSource , RegionLocationHint , Source } from './types' ;
5+ import { corsHeaders , corsPreflight } from './cors' ;
56export { DatabaseDurableObject } from './do' ;
67
78const DURABLE_OBJECT_ID = 'sql-durable-object' ;
@@ -52,6 +53,9 @@ export default {
5253 const pathname = url . pathname ;
5354 const isWebSocket = request . headers . get ( "Upgrade" ) === "websocket" ;
5455
56+ // Authorize the request with CORS rules before proceeding.
57+ corsPreflight ( request ) ;
58+
5559 /**
5660 * If the request is a GET request to the /studio endpoint, we can handle the request
5761 * directly in the Worker to avoid the need to deploy a separate Worker for the Studio.
@@ -105,8 +109,7 @@ export default {
105109 }
106110 } ;
107111
108- const response = await new Handler ( ) . handle ( request , dataSource , env ) ;
109- return response ;
112+ return await new Handler ( ) . handle ( request , dataSource , env ) ;
110113 } catch ( error ) {
111114 // Return error response to client
112115 return createResponse (
Original file line number Diff line number Diff line change 1+ import { corsHeaders } from "./cors" ;
2+
13export type QueryTransactionRequest = {
24 transaction ?: QueryRequest [ ] ;
35}
@@ -21,6 +23,7 @@ export function createJSONResponse(data: ServerResponse): Response {
2123 status : data . status ,
2224 headers : {
2325 'Content-Type' : 'application/json' ,
26+ ...corsHeaders
2427 } ,
2528 } ) ;
2629}
You can’t perform that action at this time.
0 commit comments