mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-25 03:42:30 +00:00
Update @cloudflare/next-on-pages to 1.9.0 (#156)
This commit is contained in:
+1
-1
@@ -61,7 +61,7 @@
|
||||
"devDependencies": {
|
||||
"@argos-ci/cli": "^1.0.4",
|
||||
"@argos-ci/puppeteer": "^1.2.1",
|
||||
"@cloudflare/next-on-pages": "beta",
|
||||
"@cloudflare/next-on-pages": "^1.9.0",
|
||||
"@cloudflare/workers-types": "^4.20231218.0",
|
||||
"@types/js-cookie": "^3.0.6",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
|
||||
+3
-22
@@ -1,21 +1,11 @@
|
||||
import { getRequestContext } from '@cloudflare/next-on-pages';
|
||||
|
||||
const cloudflareRequestContextSymbol = Symbol.for('__cloudflare-request-context__');
|
||||
import { getOptionalRequestContext } from '@cloudflare/next-on-pages';
|
||||
|
||||
/**
|
||||
* Get a global context object for the current request.
|
||||
* This object can be used as a key to store request-specific data in a WeakMap.
|
||||
*/
|
||||
export function getGlobalContext(): object {
|
||||
// See https://github.com/cloudflare/next-on-pages/discussions/596#discussioncomment-8450986
|
||||
// we need a reliable object that will be different per request
|
||||
const cloudflareRequestContext = (
|
||||
globalThis as unknown as {
|
||||
[cloudflareRequestContextSymbol]: object;
|
||||
}
|
||||
)[cloudflareRequestContextSymbol];
|
||||
|
||||
return cloudflareRequestContext ?? globalThis;
|
||||
return getOptionalRequestContext() ?? globalThis;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,19 +13,10 @@ export function getGlobalContext(): object {
|
||||
* https://developers.cloudflare.com/workers/runtime-apis/handlers/fetch/#contextwaituntil
|
||||
*/
|
||||
export async function waitUntil(promise: Promise<unknown>) {
|
||||
const cloudflare = getCloudflareContext();
|
||||
const cloudflare = getOptionalRequestContext();
|
||||
if (cloudflare) {
|
||||
cloudflare.ctx.waitUntil(promise);
|
||||
} else {
|
||||
await promise;
|
||||
}
|
||||
}
|
||||
|
||||
function getCloudflareContext() {
|
||||
try {
|
||||
const cloudflare = getRequestContext();
|
||||
return cloudflare;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user