File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 1+ import { Buffer } from 'node:buffer'
12import { promises as fs } from 'node:fs'
23import { env , version as nodeVersion } from 'node:process'
34
@@ -429,3 +430,34 @@ test('Returns a signed URL or the blob directly based on the request parameters'
429430 await server . stop ( )
430431 await fs . rm ( directory . path , { force : true , recursive : true } )
431432} )
433+
434+ test ( 'Accepts stores with `experimentalRegion`' , async ( ) => {
435+ const deployID = '655f77a1b48f470008e5879a'
436+ const directory = await tmp . dir ( )
437+ const server = new BlobsServer ( {
438+ directory : directory . path ,
439+ token,
440+ } )
441+ const { port } = await server . start ( )
442+
443+ const context = {
444+ deployID,
445+ edgeURL : `http://localhost:${ port } ` ,
446+ primaryRegion : 'us-east-1' ,
447+ siteID,
448+ token,
449+ }
450+
451+ env . NETLIFY_BLOBS_CONTEXT = Buffer . from ( JSON . stringify ( context ) ) . toString ( 'base64' )
452+
453+ const store = getDeployStore ( { experimentalRegion : 'context' } )
454+ const key = 'my-key'
455+ const value = 'hello from a deploy store'
456+
457+ await store . set ( key , value )
458+
459+ expect ( await store . get ( key ) ) . toBe ( value )
460+
461+ await server . stop ( )
462+ await fs . rm ( directory . path , { force : true , recursive : true } )
463+ } )
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import { isNodeError, Logger } from './util.ts'
1616const API_URL_PATH = / \/ a p i \/ v 1 \/ b l o b s \/ (?< site_id > [ ^ / ] + ) \/ (?< store_name > [ ^ / ] + ) \/ ? (?< key > [ ^ ? ] * ) /
1717const LEGACY_API_URL_PATH = / \/ a p i \/ v 1 \/ s i t e s \/ (?< site_id > [ ^ / ] + ) \/ b l o b s \/ ? (?< key > [ ^ ? ] * ) /
1818const LEGACY_DEFAULT_STORE = 'production'
19+ const REGION_PREFIX = 'region:'
1920
2021export enum Operation {
2122 DELETE = 'delete' ,
@@ -335,7 +336,13 @@ export class BlobsServer {
335336 return { }
336337 }
337338
338- const [ , siteID , rawStoreName , ...key ] = url . pathname . split ( '/' )
339+ let parts = url . pathname . split ( '/' ) . slice ( 1 )
340+
341+ if ( parts [ 0 ] . startsWith ( REGION_PREFIX ) ) {
342+ parts = parts . slice ( 1 )
343+ }
344+
345+ const [ siteID , rawStoreName , ...key ] = parts
339346
340347 if ( ! siteID ) {
341348 return { }
You can’t perform that action at this time.
0 commit comments