Skip to content

Commit 946dac8

Browse files
committed
chore: cleaned up blob storage check
1 parent dfc5f21 commit 946dac8

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

packages/runtime/src/helpers/blobStorage.ts

+13
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,16 @@ export const getBlobStorage = async ({
3232

3333
return blobs
3434
}
35+
36+
export const isBlobStorageAvailable = async ({ deployId, netliBlob }: { deployId: string; netliBlob: Blobs }) => {
37+
if (deployId === '0' || deployId !== undefined) {
38+
return false
39+
}
40+
41+
try {
42+
await netliBlob.get('test')
43+
return true
44+
} catch {
45+
return false
46+
}
47+
}

packages/runtime/src/helpers/functions.ts

+8-18
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { getHandler } from '../templates/getHandler'
2929
import { getResolverForPages, getResolverForSourceFiles } from '../templates/getPageResolver'
3030

3131
import { ApiConfig, extractConfigFromFile, isEdgeConfig } from './analysis'
32-
import { getBlobStorage } from './blobStorage'
32+
import { getBlobStorage, isBlobStorageAvailable } from './blobStorage'
3333
import { getRequiredServerFiles } from './config'
3434
import { getDependenciesOfFile, getServerFile, getSourceFileForPage } from './files'
3535
import { writeFunctionConfiguration } from './functionsMetaData'
@@ -469,11 +469,9 @@ type EnhancedNetlifyPluginConstants = NetlifyPluginConstants & {
469469
export const getSSRLambdas = async ({
470470
publish,
471471
constants,
472-
featureFlags,
473472
}: {
474473
publish: string
475474
constants: EnhancedNetlifyPluginConstants
476-
featureFlags: Record<string, unknown>
477475
}): Promise<SSRLambda[]> => {
478476
const commonDependencies = await getCommonDependencies(publish)
479477
const ssrRoutes = await getSSRRoutes(publish)
@@ -483,27 +481,19 @@ export const getSSRLambdas = async ({
483481
const odbRoutes = ssrRoutes
484482
const { NETLIFY_API_HOST, NETLIFY_API_TOKEN, SITE_ID } = constants
485483

486-
console.dir(featureFlags)
487-
488-
// This check could be improved via featureFlags exposed in the build for blob storage
489-
const isUsingBlobStorage =
490-
destr(featureFlags['netlify-server-netliblob']) &&
491-
destr(featureFlags['proxy-inject-netliblob-token']) &&
492-
process.env.DEPLOY_ID !== '0' &&
493-
process.env.DEPLOY_ID !== undefined
484+
const netliBlob = await getBlobStorage({
485+
apiHost: NETLIFY_API_HOST,
486+
token: NETLIFY_API_TOKEN,
487+
siteID: SITE_ID,
488+
deployId: process.env.DEPLOY_ID,
489+
})
494490

495491
const prerenderManifest = await getPrerenderManifest(publish)
496492
let ssrDependencies: Awaited<ReturnType<typeof getPrerenderedContent>>
497493

498-
if (isUsingBlobStorage) {
494+
if (await isBlobStorageAvailable({ deployId: process.env.DEPLOY_ID, netliBlob })) {
499495
console.log('using blob storage')
500496
ssrDependencies = []
501-
const netliBlob = await getBlobStorage({
502-
apiHost: NETLIFY_API_HOST,
503-
token: NETLIFY_API_TOKEN,
504-
siteID: SITE_ID,
505-
deployId: process.env.DEPLOY_ID,
506-
})
507497

508498
try {
509499
console.log('warming up the cache with prerendered content')

packages/runtime/src/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,7 @@ const plugin: NetlifyPlugin = {
171171
: await getExtendedApiRouteConfigs(publish, appDir, pageExtensions).then((extendedRoutes) =>
172172
extendedRoutes.map(packSingleFunction),
173173
)
174-
const ssrLambdas = bundleBasedOnNftFiles(featureFlags)
175-
? await getSSRLambdas({ publish, constants, featureFlags })
176-
: []
174+
const ssrLambdas = bundleBasedOnNftFiles(featureFlags) ? await getSSRLambdas({ publish, constants }) : []
177175
await generateFunctions(constants, appDir, apiLambdas, ssrLambdas)
178176
await generatePagesResolver(constants)
179177

0 commit comments

Comments
 (0)