Skip to content

Commit 3bdf075

Browse files
fix: set Blobs region in serve command (#6597)
1 parent 33d2c2c commit 3bdf075

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/lib/blobs/blobs.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getPathInProject } from '../settings.js'
1010
interface BaseBlobsContext {
1111
deployID: string
1212
siteID: string
13+
primaryRegion?: string
1314
token: string
1415
}
1516

@@ -27,6 +28,7 @@ export type BlobsContext = BlobsContextWithAPIAccess | BlobsContextWithEdgeAcces
2728
let hasPrintedLocalBlobsNotice = false
2829

2930
export const BLOBS_CONTEXT_VARIABLE = 'NETLIFY_BLOBS_CONTEXT'
31+
const DEV_REGION = 'dev'
3032

3133
const printLocalBlobsNotice = () => {
3234
if (hasPrintedLocalBlobsNotice) {
@@ -76,6 +78,7 @@ export const getBlobsContextWithAPIAccess = async ({ debug, projectRoot, siteID
7678
const context: BlobsContextWithAPIAccess = {
7779
apiURL: url,
7880
deployID: '0',
81+
primaryRegion: DEV_REGION,
7982
siteID,
8083
token,
8184
}
@@ -95,11 +98,23 @@ export const getBlobsContextWithEdgeAccess = async ({ debug, projectRoot, siteID
9598
siteID,
9699
token,
97100
uncachedEdgeURL: url,
101+
primaryRegion: DEV_REGION,
98102
}
99103

100104
return context
101105
}
102106

107+
/**
108+
* Returns the Blobs metadata that should be added to the Lambda event when
109+
* invoking a serverless function.
110+
*/
111+
export const getBlobsEventProperty = (context: BlobsContextWithEdgeAccess) => ({
112+
primary_region: context.primaryRegion,
113+
url: context.edgeURL,
114+
url_uncached: context.edgeURL,
115+
token: context.token,
116+
})
117+
103118
/**
104119
* Returns a Base-64, JSON-encoded representation of the Blobs context. This is
105120
* the format that the `@netlify/blobs` package expects to find the context in.

src/lib/functions/netlify-function.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import semver from 'semver'
77

88
import { error as errorExit } from '../../utils/command-helpers.js'
99
import { BACKGROUND } from '../../utils/functions/get-functions.js'
10-
import type { BlobsContextWithEdgeAccess } from '../blobs/blobs.js'
10+
import { BlobsContextWithEdgeAccess, getBlobsEventProperty } from '../blobs/blobs.js'
1111

1212
const TYPESCRIPT_EXTENSIONS = new Set(['.cts', '.mts', '.ts'])
1313
const V2_MIN_NODE_VERSION = '18.14.0'
@@ -237,11 +237,7 @@ export default class NetlifyFunction {
237237
const environment = {}
238238

239239
if (this.blobsContext) {
240-
const payload = JSON.stringify({
241-
url: this.blobsContext.edgeURL,
242-
url_uncached: this.blobsContext.edgeURL,
243-
token: this.blobsContext.token,
244-
})
240+
const payload = JSON.stringify(getBlobsEventProperty(this.blobsContext))
245241

246242
// @ts-expect-error TS(2339) FIXME: Property 'blobs' does not exist on type '{}'.
247243
event.blobs = Buffer.from(payload).toString('base64')

0 commit comments

Comments
 (0)