mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
cli: update deps
This commit is contained in:
2368
apps/web/.open-next/middleware/handler.mjs
Normal file
2368
apps/web/.open-next/middleware/handler.mjs
Normal file
File diff suppressed because one or more lines are too long
205
apps/web/.open-next/middleware/open-next.config.mjs
Normal file
205
apps/web/.open-next/middleware/open-next.config.mjs
Normal file
@@ -0,0 +1,205 @@
|
||||
// ../../node_modules/@opennextjs/cloudflare/dist/api/cloudflare-context.js
|
||||
var cloudflareContextSymbol = Symbol.for("__cloudflare-context__");
|
||||
function getCloudflareContext(options = { async: false }) {
|
||||
return options.async ? getCloudflareContextAsync() : getCloudflareContextSync();
|
||||
}
|
||||
function getCloudflareContextFromGlobalScope() {
|
||||
const global = globalThis;
|
||||
return global[cloudflareContextSymbol];
|
||||
}
|
||||
function inSSG() {
|
||||
const global = globalThis;
|
||||
return global.__NEXT_DATA__?.nextExport === true;
|
||||
}
|
||||
function getCloudflareContextSync() {
|
||||
const cloudflareContext = getCloudflareContextFromGlobalScope();
|
||||
if (cloudflareContext) {
|
||||
return cloudflareContext;
|
||||
}
|
||||
if (inSSG()) {
|
||||
throw new Error(`
|
||||
|
||||
ERROR: \`getCloudflareContext\` has been called in sync mode in either a static route or at the top level of a non-static one, both cases are not allowed but can be solved by either:
|
||||
- make sure that the call is not at the top level and that the route is not static
|
||||
- call \`getCloudflareContext({async: true})\` to use the \`async\` mode
|
||||
- avoid calling \`getCloudflareContext\` in the route
|
||||
`);
|
||||
}
|
||||
throw new Error(initOpenNextCloudflareForDevErrorMsg);
|
||||
}
|
||||
async function getCloudflareContextAsync() {
|
||||
const cloudflareContext = getCloudflareContextFromGlobalScope();
|
||||
if (cloudflareContext) {
|
||||
return cloudflareContext;
|
||||
}
|
||||
const inNodejsRuntime = process.env.NEXT_RUNTIME === "nodejs";
|
||||
if (inNodejsRuntime || inSSG()) {
|
||||
const cloudflareContext2 = await getCloudflareContextFromWrangler();
|
||||
addCloudflareContextToNodejsGlobal(cloudflareContext2);
|
||||
return cloudflareContext2;
|
||||
}
|
||||
throw new Error(initOpenNextCloudflareForDevErrorMsg);
|
||||
}
|
||||
function addCloudflareContextToNodejsGlobal(cloudflareContext) {
|
||||
const global = globalThis;
|
||||
global[cloudflareContextSymbol] = cloudflareContext;
|
||||
}
|
||||
async function getCloudflareContextFromWrangler(options) {
|
||||
const { getPlatformProxy } = await import(
|
||||
/* webpackIgnore: true */
|
||||
`${"__wrangler".replaceAll("_", "")}`
|
||||
);
|
||||
const environment = options?.environment ?? process.env.NEXT_DEV_WRANGLER_ENV;
|
||||
const { env, cf, ctx } = await getPlatformProxy({
|
||||
...options,
|
||||
environment
|
||||
});
|
||||
return {
|
||||
env,
|
||||
cf,
|
||||
ctx
|
||||
};
|
||||
}
|
||||
var initOpenNextCloudflareForDevErrorMsg = `
|
||||
|
||||
ERROR: \`getCloudflareContext\` has been called without having called \`initOpenNextCloudflareForDev\` from the Next.js config file.
|
||||
You should update your Next.js config file as shown below:
|
||||
|
||||
\`\`\`
|
||||
// next.config.mjs
|
||||
|
||||
import { initOpenNextCloudflareForDev } from "@opennextjs/cloudflare";
|
||||
|
||||
initOpenNextCloudflareForDev();
|
||||
|
||||
const nextConfig = { ... };
|
||||
export default nextConfig;
|
||||
\`\`\`
|
||||
|
||||
`;
|
||||
|
||||
// ../../node_modules/@opennextjs/cloudflare/dist/api/overrides/asset-resolver/index.js
|
||||
var resolver = {
|
||||
name: "cloudflare-asset-resolver",
|
||||
async maybeGetAssetResult(event) {
|
||||
const { ASSETS } = getCloudflareContext().env;
|
||||
if (!ASSETS || !isUserWorkerFirst(globalThis.__ASSETS_RUN_WORKER_FIRST__, event.rawPath)) {
|
||||
return void 0;
|
||||
}
|
||||
const { method, headers } = event;
|
||||
if (method !== "GET" && method != "HEAD") {
|
||||
return void 0;
|
||||
}
|
||||
const url = new URL(event.rawPath, "https://assets.local");
|
||||
const response = await ASSETS.fetch(url, {
|
||||
headers,
|
||||
method
|
||||
});
|
||||
if (response.status === 404) {
|
||||
return void 0;
|
||||
}
|
||||
return {
|
||||
type: "core",
|
||||
statusCode: response.status,
|
||||
headers: Object.fromEntries(response.headers.entries()),
|
||||
// Workers and Node types differ.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
body: response.body || new ReadableStream(),
|
||||
isBase64Encoded: false
|
||||
};
|
||||
}
|
||||
};
|
||||
function isUserWorkerFirst(runWorkerFirst, pathname) {
|
||||
if (!Array.isArray(runWorkerFirst)) {
|
||||
return runWorkerFirst ?? false;
|
||||
}
|
||||
let hasPositiveMatch = false;
|
||||
for (let rule of runWorkerFirst) {
|
||||
let isPositiveRule = true;
|
||||
if (rule.startsWith("!")) {
|
||||
rule = rule.slice(1);
|
||||
isPositiveRule = false;
|
||||
} else if (hasPositiveMatch) {
|
||||
continue;
|
||||
}
|
||||
const match = new RegExp(`^${rule.replace(/([[\]().*+?^$|{}\\])/g, "\\$1").replace("\\*", ".*")}$`).test(pathname);
|
||||
if (match) {
|
||||
if (isPositiveRule) {
|
||||
hasPositiveMatch = true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasPositiveMatch;
|
||||
}
|
||||
var asset_resolver_default = resolver;
|
||||
|
||||
// ../../node_modules/@opennextjs/cloudflare/dist/api/config.js
|
||||
function defineCloudflareConfig(config = {}) {
|
||||
const { incrementalCache, tagCache, queue, cachePurge, enableCacheInterception = false, routePreloadingBehavior = "none" } = config;
|
||||
return {
|
||||
default: {
|
||||
override: {
|
||||
wrapper: "cloudflare-node",
|
||||
converter: "edge",
|
||||
proxyExternalRequest: "fetch",
|
||||
incrementalCache: resolveIncrementalCache(incrementalCache),
|
||||
tagCache: resolveTagCache(tagCache),
|
||||
queue: resolveQueue(queue),
|
||||
cdnInvalidation: resolveCdnInvalidation(cachePurge)
|
||||
},
|
||||
routePreloadingBehavior
|
||||
},
|
||||
// node:crypto is used to compute cache keys
|
||||
edgeExternals: ["node:crypto"],
|
||||
cloudflare: {
|
||||
useWorkerdCondition: true
|
||||
},
|
||||
dangerous: {
|
||||
enableCacheInterception
|
||||
},
|
||||
middleware: {
|
||||
external: true,
|
||||
override: {
|
||||
wrapper: "cloudflare-edge",
|
||||
converter: "edge",
|
||||
proxyExternalRequest: "fetch",
|
||||
incrementalCache: resolveIncrementalCache(incrementalCache),
|
||||
tagCache: resolveTagCache(tagCache),
|
||||
queue: resolveQueue(queue)
|
||||
},
|
||||
assetResolver: () => asset_resolver_default
|
||||
}
|
||||
};
|
||||
}
|
||||
function resolveIncrementalCache(value = "dummy") {
|
||||
if (typeof value === "string") {
|
||||
return value;
|
||||
}
|
||||
return typeof value === "function" ? value : () => value;
|
||||
}
|
||||
function resolveTagCache(value = "dummy") {
|
||||
if (typeof value === "string") {
|
||||
return value;
|
||||
}
|
||||
return typeof value === "function" ? value : () => value;
|
||||
}
|
||||
function resolveQueue(value = "dummy") {
|
||||
if (typeof value === "string") {
|
||||
return value;
|
||||
}
|
||||
return typeof value === "function" ? value : () => value;
|
||||
}
|
||||
function resolveCdnInvalidation(value = "dummy") {
|
||||
if (typeof value === "string") {
|
||||
return value;
|
||||
}
|
||||
return typeof value === "function" ? value : () => value;
|
||||
}
|
||||
|
||||
// open-next.config.ts
|
||||
var open_next_config_default = defineCloudflareConfig();
|
||||
export {
|
||||
open_next_config_default as default
|
||||
};
|
||||
Reference in New Issue
Block a user