Skip to content

Commit aec9c41

Browse files
authored
Merge pull request #7 from netlify/tn/blob
feat: move pre-rendered content to blob store
2 parents a0e594c + f471107 commit aec9c41

File tree

8 files changed

+232
-134
lines changed

8 files changed

+232
-134
lines changed

package-lock.json

+73-81
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@
4040
"@netlify/functions": "^2.0.1",
4141
"@vercel/nft": "^0.24.3",
4242
"fs-extra": "^11.1.1",
43-
"globby": "^13.2.2"
43+
"globby": "^13.2.2",
44+
"os": "^0.1.2",
45+
"outdent": "^0.8.0",
46+
"p-limit": "^4.0.0"
4447
},
4548
"devDependencies": {
4649
"@netlify/eslint-config-node": "^7.0.1",

src/handlers/server.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable n/prefer-global/buffer */
12
import { toComputeResponse, toReqRes } from '@fastly/http-compute-js'
23
import type { HeadersSentEvent } from '@fastly/http-compute-js/dist/http-compute-js/http-outgoing.js'
34
import type { NextConfigComplete } from 'next/dist/server/config-shared.js'

src/helpers/blobs.ts

+7-35
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,10 @@
1-
import { Blobs } from '@netlify/blobs'
2-
import type { Blobs as IBlobs } from '@netlify/blobs'
1+
import { getStore } from '@netlify/blobs'
32

4-
let blobs: IBlobs
5-
6-
export const getBlobStorage = ({
7-
apiHost,
8-
token,
9-
siteID,
10-
deployId,
11-
}: {
12-
apiHost: string | undefined
13-
token: string | undefined
14-
siteID: string
15-
deployId: string | undefined
16-
}) => {
17-
if (!blobs && apiHost && token && siteID && deployId) {
18-
blobs = new Blobs({
19-
authentication: {
20-
apiURL: `https://${apiHost}`,
21-
token,
22-
},
23-
context: `deploy:${deployId}`,
24-
siteID,
25-
})
26-
}
27-
28-
return blobs
29-
}
30-
31-
export const isBlobStorageAvailable = async (netliBlob: IBlobs) => {
32-
try {
33-
await netliBlob.get('test')
34-
return true
35-
} catch {
36-
return false
3+
export const netliBlob = (token: string, deployID: string, siteID: string, apiURL?: string) => {
4+
const storeAuth = { deployID, siteID, token, apiURL }
5+
// apiURL uses default on build so we only preserve context if apiURL is set within handler function
6+
if (apiURL) {
7+
process.env.NETLIFY_BLOBS_CONTEXT = btoa(JSON.stringify(storeAuth))
378
}
9+
return getStore(storeAuth)
3810
}

0 commit comments

Comments
 (0)