@@ -16,11 +16,25 @@ const DURABLE_OBJECT_ID = 'sql-durable-object';
1616interface Env {
1717 AUTHORIZATION_TOKEN : string ;
1818 DATABASE_DURABLE_OBJECT : DurableObjectNamespace ;
19+ REGION : string ;
1920 STUDIO_USER ?: string ;
2021 STUDIO_PASS ?: string ;
2122 // ## DO NOT REMOVE: TEMPLATE INTERFACE ##
2223}
2324
25+ enum RegionLocationHint {
26+ AUTO = 'auto' ,
27+ WNAM = 'wnam' , // Western North America
28+ ENAM = 'enam' , // Eastern North America
29+ SAM = 'sam' , // South America
30+ WEUR = 'weur' , // Western Europe
31+ EEUR = 'eeur' , // Eastern Europe
32+ APAC = 'apac' , // Asia Pacific
33+ OC = 'oc' , // Oceania
34+ AFR = 'afr' , // Africa
35+ ME = 'me' , // Middle East
36+ }
37+
2438export class DatabaseDurableObject extends DurableObject {
2539 // Durable storage for the SQL database
2640 public sql : SqlStorage ;
@@ -165,6 +179,11 @@ export class DatabaseDurableObject extends DurableObject {
165179 return this . clientConnected ( ) ;
166180 } else if ( request . method === 'GET' && url . pathname === '/status' ) {
167181 return this . statusRoute ( request ) ;
182+ } else if ( request . method === 'GET' && url . pathname === '/status/trace' ) {
183+ const response = await fetch ( 'https://cloudflare.com/cdn-cgi/trace' ) ;
184+ return new Response ( response . body , {
185+ headers : response . headers
186+ } ) ;
168187 } else if ( url . pathname . startsWith ( '/rest' ) ) {
169188 return await this . liteREST . handleRequest ( request ) ;
170189 } else if ( request . method === 'GET' && url . pathname === '/export/dump' ) {
@@ -294,8 +313,9 @@ export default {
294313 * Retrieve the Durable Object identifier from the environment bindings and instantiate a
295314 * Durable Object stub to interact with the Durable Object.
296315 */
297- let id : DurableObjectId = env . DATABASE_DURABLE_OBJECT . idFromName ( DURABLE_OBJECT_ID ) ;
298- let stub = env . DATABASE_DURABLE_OBJECT . get ( id ) ;
316+ const region = env . REGION ?? RegionLocationHint . AUTO ;
317+ const id : DurableObjectId = env . DATABASE_DURABLE_OBJECT . idFromName ( DURABLE_OBJECT_ID ) ;
318+ const stub = region !== RegionLocationHint . AUTO ? env . DATABASE_DURABLE_OBJECT . get ( id , { locationHint : region as DurableObjectLocationHint } ) : env . DATABASE_DURABLE_OBJECT . get ( id ) ;
299319
300320 // ## DO NOT REMOVE: TEMPLATE ROUTING ##
301321
0 commit comments