@@ -3,6 +3,7 @@ import { StarbaseDB, StarbaseDBConfiguration } from "./handler";
33import { DataSource , RegionLocationHint } from "./types" ;
44import { createRemoteJWKSet , jwtVerify } from "jose" ;
55import { handleStudioRequest } from "./studio" ;
6+ import { corsPreflight } from "./cors" ;
67
78export { StarbaseDBDurableObject } from "./do" ;
89
@@ -43,7 +44,6 @@ export interface Env {
4344 EXTERNAL_DB_CLOUDFLARE_DATABASE_ID ?: string ;
4445
4546 AUTH_ALGORITHM ?: string ;
46- AUTH_JWT_SECRET ?: string ;
4747 AUTH_JWKS_ENDPOINT ?: string ;
4848
4949 // ## DO NOT REMOVE: TEMPLATE INTERFACE ##
@@ -66,6 +66,15 @@ export default {
6666 let role : StarbaseDBConfiguration [ "role" ] = "client" ;
6767 let context = { } ;
6868
69+ // Authorize the request with CORS rules before proceeding.
70+ if ( request . method === "OPTIONS" ) {
71+ const preflightResponse = corsPreflight ( ) ;
72+
73+ if ( preflightResponse ) {
74+ return preflightResponse ;
75+ }
76+ }
77+
6978 // Handle Studio requests before auth checks in the worker.
7079 // StarbaseDB can handle this for us, but we need to handle it
7180 // here before auth checks.
@@ -88,7 +97,7 @@ export default {
8897
8998 // If not admin or client auth, check if JWT auth is available
9099 if ( ! isAdminAuthorization && ! isClientAuthorization ) {
91- if ( env . AUTH_JWT_SECRET && env . AUTH_JWKS_ENDPOINT ) {
100+ if ( env . AUTH_JWKS_ENDPOINT ) {
92101 const { payload } = await jwtVerify (
93102 token ,
94103 createRemoteJWKSet ( new URL ( env . AUTH_JWKS_ENDPOINT ) ) ,
0 commit comments