nitro-nightly 3.0.1-20251209-203952-cd9c2915 → 3.0.1-20251210-091123-c1787f75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_presets.mjs +9 -4
- package/dist/presets/vercel/runtime/isr.d.mts +2 -0
- package/dist/presets/vercel/runtime/isr.mjs +19 -0
- package/dist/presets/vercel/runtime/vercel.node.mjs +8 -6
- package/dist/presets/vercel/runtime/vercel.web.mjs +8 -8
- package/dist/runtime/app.d.mts +1 -1
- package/dist/runtime/app.mjs +1 -1
- package/dist/runtime/internal/app.d.mts +6 -2
- package/dist/runtime/internal/app.mjs +1 -1
- package/package.json +1 -1
package/dist/_presets.mjs
CHANGED
|
@@ -1359,6 +1359,10 @@ const stormkit = defineNitroPreset({
|
|
|
1359
1359
|
});
|
|
1360
1360
|
var preset_default$22 = [stormkit];
|
|
1361
1361
|
|
|
1362
|
+
//#endregion
|
|
1363
|
+
//#region src/presets/vercel/runtime/isr.ts
|
|
1364
|
+
const ISR_URL_PARAM = "__isr_route";
|
|
1365
|
+
|
|
1362
1366
|
//#endregion
|
|
1363
1367
|
//#region src/presets/vercel/utils.ts
|
|
1364
1368
|
const SUPPORTED_NODE_VERSIONS = [20, 22];
|
|
@@ -1439,17 +1443,17 @@ function generateBuildConfig(nitro, o11Routes) {
|
|
|
1439
1443
|
});
|
|
1440
1444
|
if (nitro.options.static) return config;
|
|
1441
1445
|
config.routes.push(...nitro.options.routeRules["/"]?.isr ? [{
|
|
1442
|
-
src:
|
|
1443
|
-
dest: `/index${ISR_SUFFIX}
|
|
1446
|
+
src: `(?<${ISR_URL_PARAM}>/)`,
|
|
1447
|
+
dest: `/index${ISR_SUFFIX}?${ISR_URL_PARAM}=$${ISR_URL_PARAM}`
|
|
1444
1448
|
}] : [], ...rules.filter(([key, value]) => value.isr !== void 0 && key !== "/").map(([key, value]) => {
|
|
1445
|
-
const src =
|
|
1449
|
+
const src = `(?<${ISR_URL_PARAM}>${normalizeRouteSrc(key)})`;
|
|
1446
1450
|
if (value.isr === false) return {
|
|
1447
1451
|
src,
|
|
1448
1452
|
dest: FALLBACK_ROUTE
|
|
1449
1453
|
};
|
|
1450
1454
|
return {
|
|
1451
1455
|
src,
|
|
1452
|
-
dest: withLeadingSlash(normalizeRouteDest(key) + ISR_SUFFIX +
|
|
1456
|
+
dest: withLeadingSlash(normalizeRouteDest(key) + ISR_SUFFIX + `?${ISR_URL_PARAM}=$${ISR_URL_PARAM}`)
|
|
1453
1457
|
};
|
|
1454
1458
|
}), ...(o11Routes || []).map((route) => ({
|
|
1455
1459
|
src: joinURL(nitro.options.baseURL, route.src),
|
|
@@ -1549,6 +1553,7 @@ async function writePrerenderConfig(filename, isrConfig, bypassToken) {
|
|
|
1549
1553
|
bypassToken,
|
|
1550
1554
|
...isrConfig
|
|
1551
1555
|
};
|
|
1556
|
+
if (prerenderConfig.allowQuery && !prerenderConfig.allowQuery.includes(ISR_URL_PARAM)) prerenderConfig.allowQuery.push(ISR_URL_PARAM);
|
|
1552
1557
|
await writeFile$1(filename, JSON.stringify(prerenderConfig, null, 2));
|
|
1553
1558
|
}
|
|
1554
1559
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const ISR_URL_PARAM = "__isr_route";
|
|
2
|
+
export function isrRouteRewrite(reqUrl, xNowRouteMatches) {
|
|
3
|
+
if (xNowRouteMatches) {
|
|
4
|
+
const isrURL = new URLSearchParams(xNowRouteMatches).get(ISR_URL_PARAM);
|
|
5
|
+
if (isrURL) {
|
|
6
|
+
return [decodeURIComponent(isrURL), ""];
|
|
7
|
+
}
|
|
8
|
+
} else {
|
|
9
|
+
const queryIndex = reqUrl.indexOf("?");
|
|
10
|
+
if (queryIndex !== -1) {
|
|
11
|
+
const params = new URLSearchParams(reqUrl.slice(queryIndex + 1));
|
|
12
|
+
const isrURL = params.get(ISR_URL_PARAM);
|
|
13
|
+
if (isrURL) {
|
|
14
|
+
params.delete(ISR_URL_PARAM);
|
|
15
|
+
return [decodeURIComponent(isrURL), params.toString()];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import "#nitro-internal-polyfills";
|
|
2
2
|
import { toNodeHandler } from "srvx/node";
|
|
3
|
-
import { useNitroApp } from "nitro/app";
|
|
3
|
+
import { useNitroApp, getRouteRules } from "nitro/app";
|
|
4
|
+
import { isrRouteRewrite } from "./isr.mjs";
|
|
4
5
|
const nitroApp = useNitroApp();
|
|
5
6
|
const handler = toNodeHandler(nitroApp.fetch);
|
|
6
7
|
export default function nodeHandler(req, res) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
// ISR route rewrite
|
|
9
|
+
const isrURL = isrRouteRewrite(req.url, req.headers["x-now-route-matches"]);
|
|
10
|
+
if (isrURL) {
|
|
11
|
+
const { routeRules } = getRouteRules("", isrURL[0]);
|
|
12
|
+
if (routeRules?.isr) {
|
|
13
|
+
req.url = isrURL[0] + (isrURL[1] ? `?${isrURL[1]}` : "");
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
return handler(req, res);
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import "#nitro-internal-polyfills";
|
|
2
|
-
import { useNitroApp } from "nitro/app";
|
|
2
|
+
import { useNitroApp, getRouteRules } from "nitro/app";
|
|
3
|
+
import { isrRouteRewrite } from "./isr.mjs";
|
|
3
4
|
const nitroApp = useNitroApp();
|
|
4
5
|
export default { fetch(req, context) {
|
|
5
|
-
//
|
|
6
|
-
const
|
|
7
|
-
if (
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
req = new Request(url, req);
|
|
6
|
+
// ISR route rewrite
|
|
7
|
+
const isrURL = isrRouteRewrite(req.url, req.headers.get("x-now-route-matches"));
|
|
8
|
+
if (isrURL) {
|
|
9
|
+
const { routeRules } = getRouteRules("", isrURL[0]);
|
|
10
|
+
if (routeRules?.isr) {
|
|
11
|
+
req = new Request(new URL(isrURL[0] + (isrURL[1] ? `?${isrURL[1]}` : ""), req.url).href, req);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
// srvx compatibility
|
package/dist/runtime/app.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { useNitroApp, useNitroHooks, serverFetch, fetch } from "./internal/app.mjs";
|
|
1
|
+
export { useNitroApp, useNitroHooks, serverFetch, getRouteRules, fetch } from "./internal/app.mjs";
|
package/dist/runtime/app.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { useNitroApp, useNitroHooks, serverFetch, fetch } from "./internal/app.mjs";
|
|
1
|
+
export { useNitroApp, useNitroHooks, serverFetch, getRouteRules, fetch } from "./internal/app.mjs";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { NitroApp, NitroRuntimeHooks } from "nitro/types";
|
|
1
|
+
import type { MatchedRouteRules, NitroApp, NitroRuntimeHooks } from "nitro/types";
|
|
2
2
|
import type { ServerRequest, ServerRequestContext } from "srvx";
|
|
3
|
-
import type { H3EventContext, WebSocketHooks } from "h3";
|
|
3
|
+
import type { H3EventContext, Middleware, WebSocketHooks } from "h3";
|
|
4
4
|
import { HookableCore } from "hookable";
|
|
5
5
|
declare global {
|
|
6
6
|
var __nitro__: NitroApp | undefined;
|
|
@@ -10,3 +10,7 @@ export declare function useNitroHooks(): HookableCore<NitroRuntimeHooks>;
|
|
|
10
10
|
export declare function serverFetch(resource: string | URL | Request, init?: RequestInit, context?: ServerRequestContext | H3EventContext): Promise<Response>;
|
|
11
11
|
export declare function resolveWebsocketHooks(req: ServerRequest): Promise<Partial<WebSocketHooks>>;
|
|
12
12
|
export declare function fetch(resource: string | URL | Request, init?: RequestInit, context?: ServerRequestContext | H3EventContext): Promise<Response>;
|
|
13
|
+
export declare function getRouteRules(method: string, pathname: string): {
|
|
14
|
+
routeRules?: MatchedRouteRules;
|
|
15
|
+
routeRuleMiddleware: Middleware[];
|
|
16
|
+
};
|
|
@@ -148,7 +148,7 @@ function createH3App(config) {
|
|
|
148
148
|
}
|
|
149
149
|
return h3App;
|
|
150
150
|
}
|
|
151
|
-
function getRouteRules(method, pathname) {
|
|
151
|
+
export function getRouteRules(method, pathname) {
|
|
152
152
|
const m = findRouteRules(method, pathname);
|
|
153
153
|
if (!m?.length) {
|
|
154
154
|
return { routeRuleMiddleware: [] };
|
package/package.json
CHANGED