nitro-nightly 3.0.1-alpha.1 → 3.0.1-alpha.2
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/README.md +2 -0
- package/dist/_build/common.mjs +24924 -52
- package/dist/_build/rolldown.mjs +29 -63
- package/dist/_build/rollup.mjs +22 -110
- package/dist/_build/vite.build.mjs +3 -43
- package/dist/{_dev.mjs → _chunks/dev.mjs} +45 -43
- package/dist/_chunks/{B-D1JOIz.mjs → nitro.mjs} +144 -308
- package/dist/_chunks/nitro2.mjs +101 -0
- package/dist/_chunks/utils.mjs +254 -0
- package/dist/{_chunks/Bqks5huO.mjs → _common.mjs} +24 -10
- package/dist/_libs/c12+giget+readdirp+chokidar.d.mts +214 -0
- package/dist/_libs/citty.mjs +140 -110
- package/dist/_libs/{plugin-commonjs.mjs → commondir+is-reference.mjs} +59 -250
- package/dist/_libs/compatx.d.mts +47 -0
- package/dist/_libs/confbox.mjs +388 -799
- package/dist/_libs/esbuild.d.mts +20 -0
- package/dist/_libs/estree-walker.mjs +1 -144
- package/dist/_libs/{plugin-node-resolve.mjs → hasown+resolve+deepmerge.mjs} +497 -78
- package/dist/_libs/httpxy.d.mts +79 -0
- package/dist/_libs/httpxy.mjs +6 -1
- package/dist/_libs/magic-string.d.mts +220 -0
- package/dist/_libs/mlly.d.mts +57 -0
- package/dist/_libs/nypm+giget+tinyexec.mjs +3603 -0
- package/dist/_libs/pkg-types.d.mts +23 -0
- package/dist/_libs/plugin-alias.mjs +4 -2
- package/dist/_libs/plugin-inject.mjs +5 -5
- package/dist/_libs/plugin-json.mjs +2 -2
- package/dist/_libs/pluginutils+plugin-commonjs.d.mts +241 -0
- package/dist/_libs/{vite-plugin-fullstack.mjs → pluginutils.mjs} +244 -153
- package/dist/_libs/rc9+c12+dotenv.mjs +972 -0
- package/dist/_libs/{chokidar.mjs → readdirp+chokidar.mjs} +237 -187
- package/dist/_libs/remapping.mjs +1 -1
- package/dist/_libs/{gen-mapping.mjs → resolve-uri+gen-mapping.mjs} +2 -166
- package/dist/_libs/rou3.d.mts +43 -0
- package/dist/_libs/rou3.mjs +9 -6
- package/dist/_libs/std-env.d.mts +4 -0
- package/dist/_libs/tsconfck.mjs +3 -3
- package/dist/_libs/{unimport.mjs → unimport+unplugin.mjs} +226 -1961
- package/dist/_libs/unplugin+unimport.d.mts +426 -0
- package/dist/_libs/unwasm.d.mts +29 -0
- package/dist/_presets.mjs +130 -80
- package/dist/builder.d.mts +4 -4
- package/dist/builder.mjs +6 -30
- package/dist/cli/_chunks/build.mjs +1 -1
- package/dist/cli/_chunks/dev.mjs +5 -11
- package/dist/cli/_chunks/list.mjs +1 -1
- package/dist/cli/_chunks/prepare.mjs +1 -1
- package/dist/cli/_chunks/run.mjs +1 -1
- package/dist/node_modules/@poppinss/colors/build/index.js +130 -160
- package/dist/node_modules/@poppinss/colors/package.json +20 -18
- package/dist/node_modules/@poppinss/exception/build/index.js +36 -55
- package/dist/node_modules/@poppinss/exception/package.json +19 -16
- package/dist/node_modules/@sindresorhus/is/distribution/index.js +46 -5
- package/dist/node_modules/@sindresorhus/is/package.json +1 -1
- package/dist/node_modules/@speed-highlight/core/dist/index.js +1 -1
- package/dist/node_modules/@speed-highlight/core/dist/terminal.js +1 -1
- package/dist/node_modules/@speed-highlight/core/package.json +2 -2
- package/dist/node_modules/hookable/dist/index.mjs +5 -6
- package/dist/node_modules/hookable/package.json +13 -13
- package/dist/node_modules/ufo/dist/index.mjs +16 -9
- package/dist/node_modules/ufo/package.json +15 -14
- package/dist/node_modules/unctx/package.json +16 -16
- package/dist/node_modules/youch/build/{chunk-4XB2BYKC.js → chunk-7QV3D5YX.js} +2 -4
- package/dist/node_modules/youch/build/{chunk-PUHGL6HA.js → chunk-AUGPHE32.js} +2 -4
- package/dist/node_modules/youch/build/{chunk-F4I6KX4R.js → chunk-CM7DWJNZ.js} +2 -4
- package/dist/node_modules/youch/build/{chunk-YYEJ3AGB.js → chunk-EJH674NB.js} +2 -4
- package/dist/node_modules/youch/build/{chunk-EUJBVOYB.js → chunk-OIJ3WD7L.js} +2 -4
- package/dist/node_modules/youch/build/{chunk-HFSXRSKS.js → chunk-P36L72PL.js} +5 -3
- package/dist/node_modules/youch/build/{chunk-4YEN7HVQ.js → chunk-PE3GG3TN.js} +5 -1
- package/dist/node_modules/youch/build/{chunk-PINJDICN.js → chunk-X53OIOJH.js} +2 -4
- package/dist/node_modules/youch/build/index.js +8 -9
- package/dist/node_modules/youch/build/public/error_info/style.css +1 -0
- package/dist/node_modules/youch/build/public/error_metadata/style.css +3 -0
- package/dist/node_modules/youch/build/public/error_stack/style.css +2 -3
- package/dist/node_modules/youch/package.json +1 -1
- package/dist/presets/_nitro/runtime/nitro-dev.d.mts +1 -1
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +5 -6
- package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +1 -1
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +1 -1
- package/dist/presets/_nitro/runtime/service-worker.d.mts +1 -1
- package/dist/presets/_nitro/runtime/service-worker.mjs +2 -2
- package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +1 -1
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +1 -1
- package/dist/presets/aws-lambda/runtime/_utils.d.mts +0 -5
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +1 -1
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +9 -11
- package/dist/presets/aws-lambda/runtime/aws-lambda.d.mts +1 -1
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +1 -1
- package/dist/presets/azure/runtime/azure-swa.d.mts +1 -1
- package/dist/presets/azure/runtime/azure-swa.mjs +1 -1
- package/dist/presets/bun/runtime/bun.d.mts +1 -1
- package/dist/presets/bun/runtime/bun.mjs +7 -8
- package/dist/presets/cloudflare/runtime/_module-handler.d.mts +3 -3
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +19 -17
- package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +17 -16
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +8 -9
- package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +12 -18
- package/dist/presets/deno/runtime/deno-deploy.d.mts +1 -1
- package/dist/presets/deno/runtime/deno-deploy.mjs +4 -5
- package/dist/presets/deno/runtime/deno-server.d.mts +1 -1
- package/dist/presets/deno/runtime/deno-server.mjs +5 -6
- package/dist/presets/netlify/runtime/netlify-edge.d.mts +1 -2
- package/dist/presets/netlify/runtime/netlify-edge.mjs +3 -2
- package/dist/presets/netlify/runtime/netlify.d.mts +3 -2
- package/dist/presets/netlify/runtime/netlify.mjs +3 -1
- package/dist/presets/node/runtime/node-cluster.d.mts +1 -1
- package/dist/presets/node/runtime/node-cluster.mjs +5 -6
- package/dist/presets/node/runtime/node-middleware.d.mts +1 -1
- package/dist/presets/node/runtime/node-middleware.mjs +4 -5
- package/dist/presets/node/runtime/node-server.d.mts +1 -1
- package/dist/presets/node/runtime/node-server.mjs +5 -6
- package/dist/presets/standard/runtime/server.d.mts +1 -1
- package/dist/presets/standard/runtime/server.mjs +1 -1
- package/dist/presets/stormkit/runtime/stormkit.d.mts +1 -1
- package/dist/presets/stormkit/runtime/stormkit.mjs +1 -1
- 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.d.mts +1 -1
- package/dist/presets/vercel/runtime/vercel.node.mjs +16 -7
- package/dist/presets/vercel/runtime/vercel.web.d.mts +1 -1
- package/dist/presets/vercel/runtime/vercel.web.mjs +18 -13
- package/dist/presets/winterjs/runtime/winterjs.d.mts +1 -2
- package/dist/presets/winterjs/runtime/winterjs.mjs +1 -1
- package/dist/presets/zeabur/runtime/zeabur.d.mts +1 -1
- package/dist/presets/zeabur/runtime/zeabur.mjs +1 -1
- package/dist/runtime/app.d.mts +1 -1
- package/dist/runtime/app.mjs +1 -1
- package/dist/runtime/internal/app.d.mts +7 -3
- package/dist/runtime/internal/app.mjs +29 -22
- package/dist/runtime/internal/database.mjs +1 -1
- package/dist/runtime/internal/error/dev.d.mts +0 -1
- package/dist/runtime/internal/error/dev.mjs +1 -1
- package/dist/runtime/internal/route-rules.d.mts +0 -4
- package/dist/runtime/internal/routes/dev-tasks.mjs +1 -1
- package/dist/runtime/internal/routes/openapi.d.mts +0 -1
- package/dist/runtime/internal/routes/openapi.mjs +3 -3
- package/dist/runtime/internal/routes/renderer-template.dev.mjs +1 -1
- package/dist/runtime/internal/routes/renderer-template.mjs +1 -1
- package/dist/runtime/internal/routes/scalar.d.mts +0 -1
- package/dist/runtime/internal/routes/scalar.mjs +4 -4
- package/dist/runtime/internal/routes/swagger.d.mts +0 -1
- package/dist/runtime/internal/routes/swagger.mjs +3 -3
- package/dist/runtime/internal/runtime-config.mjs +8 -8
- package/dist/runtime/internal/static.mjs +1 -1
- package/dist/runtime/internal/storage.mjs +1 -1
- package/dist/runtime/internal/task.mjs +1 -1
- package/dist/runtime/internal/vite/dev-entry.mjs +3 -4
- package/dist/runtime/internal/vite/{dev-worker.mjs → node-runner.mjs} +51 -6
- package/dist/runtime/meta.d.mts +1 -1
- package/dist/runtime/meta.mjs +1 -1
- package/dist/runtime/nitro.d.mts +0 -3
- package/dist/runtime/nitro.mjs +1 -1
- package/dist/runtime/virtual/_runtime_warn.d.mts +1 -0
- package/dist/runtime/virtual/_runtime_warn.mjs +5 -0
- package/dist/runtime/virtual/database.d.mts +8 -0
- package/dist/runtime/virtual/database.mjs +2 -0
- package/dist/runtime/virtual/error-handler.d.mts +6 -0
- package/dist/runtime/virtual/error-handler.mjs +9 -0
- package/dist/runtime/virtual/feature-flags.d.mts +7 -0
- package/dist/runtime/virtual/feature-flags.mjs +7 -0
- package/dist/runtime/virtual/plugins.d.mts +3 -0
- package/dist/runtime/virtual/plugins.mjs +2 -0
- package/dist/runtime/virtual/polyfills.d.mts +3 -0
- package/dist/runtime/virtual/polyfills.mjs +2 -0
- package/dist/runtime/virtual/public-assets.d.mts +9 -0
- package/dist/runtime/virtual/public-assets.mjs +8 -0
- package/dist/runtime/virtual/renderer-template.d.mts +4 -0
- package/dist/runtime/virtual/renderer-template.mjs +7 -0
- package/dist/runtime/virtual/routing-meta.d.mts +7 -0
- package/dist/runtime/virtual/routing-meta.mjs +2 -0
- package/dist/runtime/virtual/routing.d.mts +8 -0
- package/dist/runtime/virtual/routing.mjs +11 -0
- package/dist/runtime/virtual/runtime-config.d.mts +3 -0
- package/dist/runtime/virtual/runtime-config.mjs +5 -0
- package/dist/runtime/virtual/server-assets.d.mts +6 -0
- package/dist/runtime/virtual/server-assets.mjs +12 -0
- package/dist/runtime/virtual/storage.d.mts +3 -0
- package/dist/runtime/virtual/storage.mjs +5 -0
- package/dist/runtime/virtual/tasks.d.mts +10 -0
- package/dist/runtime/virtual/tasks.mjs +3 -0
- package/dist/types/index.d.mts +292 -371
- package/dist/types/index.mjs +10 -0
- package/dist/vite.d.mts +7 -12
- package/dist/vite.mjs +734 -41
- package/lib/vite.types.d.mts +26 -0
- package/lib/vite.types.mjs +2 -0
- package/package.json +82 -53
- package/dist/_build/common2.mjs +0 -772
- package/dist/_build/vite.plugin.mjs +0 -768
- package/dist/_chunks/ANM1K1bE.mjs +0 -304
- package/dist/_chunks/BX9-zVkM.mjs +0 -59
- package/dist/_chunks/C7CbzoI1.mjs +0 -39
- package/dist/_libs/acorn.mjs +0 -5034
- package/dist/_libs/c12.mjs +0 -2858
- package/dist/_libs/commondir.mjs +0 -22
- package/dist/_libs/deepmerge.mjs +0 -86
- package/dist/_libs/dot-prop.mjs +0 -138
- package/dist/_libs/duplexer.mjs +0 -71
- package/dist/_libs/etag.mjs +0 -80
- package/dist/_libs/fdir.mjs +0 -514
- package/dist/_libs/function-bind.mjs +0 -63
- package/dist/_libs/giget.mjs +0 -19289
- package/dist/_libs/gzip-size.mjs +0 -21
- package/dist/_libs/hasown.mjs +0 -14
- package/dist/_libs/is-core-module.mjs +0 -220
- package/dist/_libs/is-module.mjs +0 -13
- package/dist/_libs/is-reference.mjs +0 -32
- package/dist/_libs/js-tokens.mjs +0 -382
- package/dist/_libs/knitwork.mjs +0 -124
- package/dist/_libs/local-pkg.mjs +0 -1686
- package/dist/_libs/magic-string.mjs +0 -939
- package/dist/_libs/mime.mjs +0 -1391
- package/dist/_libs/node-fetch-native.mjs +0 -173
- package/dist/_libs/path-parse.mjs +0 -47
- package/dist/_libs/pathe.mjs +0 -41
- package/dist/_libs/picomatch.mjs +0 -1673
- package/dist/_libs/plugin-replace.mjs +0 -104
- package/dist/_libs/pretty-bytes.mjs +0 -116
- package/dist/_libs/std-env.mjs +0 -158
- package/dist/_libs/strip-literal.mjs +0 -51
- package/dist/_libs/tinyglobby.mjs +0 -292
- package/dist/_libs/untyped.mjs +0 -271
- package/dist/_libs/unwasm.mjs +0 -5836
- package/dist/cli/_chunks/detect-acorn.mjs +0 -12
- package/dist/cli/_chunks/dist.mjs +0 -3
- package/dist/cli/_chunks/dist2.mjs +0 -3
- package/dist/cli/_chunks/dist3.mjs +0 -3
- package/dist/cli/_chunks/dist4.mjs +0 -4
- package/dist/cli/_chunks/dist5.mjs +0 -4
- package/dist/cli/_chunks/esm.mjs +0 -3
- package/dist/cli/_chunks/json5.mjs +0 -4
- package/dist/cli/_chunks/jsonc.mjs +0 -4
- package/dist/cli/_chunks/multipart-parser.mjs +0 -6
- package/dist/cli/_chunks/toml.mjs +0 -4
- package/dist/cli/_chunks/yaml.mjs +0 -4
- package/dist/node_modules/kleur/index.js +0 -110
- package/dist/node_modules/youch/build/chunk-OSUFJZHZ.js +0 -6
- package/lib/deps/ofetch.mjs +0 -1
- package/lib/deps/ofetch.mts +0 -1
- /package/dist/runtime/{vite-runtime.d.mts → vite.d.mts} +0 -0
- /package/dist/runtime/{vite-runtime.mjs → vite.mjs} +0 -0
- /package/lib/{deps/h3.d.mts → h3.d.mts} +0 -0
- /package/lib/{deps/h3.mjs → h3.mjs} +0 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import "#nitro
|
|
1
|
+
import "#nitro/virtual/polyfills";
|
|
2
2
|
import { useNitroApp } from "nitro/app";
|
|
3
|
-
import { isPublicAssetURL } from "#nitro
|
|
3
|
+
import { isPublicAssetURL } from "#nitro/virtual/public-assets";
|
|
4
4
|
const nitroApp = useNitroApp();
|
|
5
5
|
// https://docs.netlify.com/edge-functions/api/
|
|
6
6
|
export default async function netlifyEdge(netlifyReq, context) {
|
|
7
7
|
// srvx compatibility
|
|
8
8
|
const req = netlifyReq;
|
|
9
|
+
req.ip = context.ip;
|
|
9
10
|
req.runtime ??= { name: "netlify-edge" };
|
|
10
11
|
// @ts-expect-error (add to srvx types)
|
|
11
12
|
req.runtime.netlify ??= { context };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import "#nitro
|
|
2
|
-
|
|
1
|
+
import "#nitro/virtual/polyfills";
|
|
2
|
+
import type { ServerRequest } from "srvx";
|
|
3
|
+
declare const handler: (req: ServerRequest) => Promise<Response>;
|
|
3
4
|
export default handler;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import "#nitro
|
|
1
|
+
import "#nitro/virtual/polyfills";
|
|
2
2
|
import { useNitroApp } from "nitro/app";
|
|
3
3
|
const nitroApp = useNitroApp();
|
|
4
4
|
const ONE_YEAR_IN_SECONDS = 365 * 24 * 60 * 60;
|
|
5
5
|
const handler = async (req) => {
|
|
6
|
+
req.runtime ??= { name: "netlify" };
|
|
7
|
+
req.ip = req.headers.get("x-nf-client-connection-ip") || undefined;
|
|
6
8
|
const response = await nitroApp.fetch(req);
|
|
7
9
|
const isr = (req.context?.routeRules || {})?.isr?.options;
|
|
8
10
|
if (isr) {
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import "#nitro
|
|
1
|
+
import "#nitro/virtual/polyfills";
|
|
2
2
|
import cluster from "node:cluster";
|
|
3
3
|
import { NodeRequest, serve } from "srvx/node";
|
|
4
4
|
import wsAdapter from "crossws/adapters/node";
|
|
5
5
|
import { useNitroApp } from "nitro/app";
|
|
6
|
-
import { startScheduleRunner } from "nitro
|
|
7
|
-
import { trapUnhandledErrors } from "nitro
|
|
8
|
-
import { resolveWebsocketHooks } from "nitro
|
|
9
|
-
import { hasWebSocket } from "#nitro-internal-virtual/feature-flags";
|
|
6
|
+
import { startScheduleRunner } from "#nitro/runtime/task";
|
|
7
|
+
import { trapUnhandledErrors } from "#nitro/runtime/error/hooks";
|
|
8
|
+
import { resolveWebsocketHooks } from "#nitro/runtime/app";
|
|
10
9
|
const port = Number.parseInt(process.env.NITRO_PORT || process.env.PORT || "") || 3e3;
|
|
11
10
|
const host = process.env.NITRO_HOST || process.env.HOST;
|
|
12
11
|
const cert = process.env.NITRO_SSL_CERT;
|
|
@@ -28,7 +27,7 @@ const server = serve({
|
|
|
28
27
|
silent: clusterId ? clusterId !== "1" : undefined,
|
|
29
28
|
fetch: nitroApp.fetch
|
|
30
29
|
});
|
|
31
|
-
if (
|
|
30
|
+
if (import.meta._websocket) {
|
|
32
31
|
const { handleUpgrade } = wsAdapter({ resolve: resolveWebsocketHooks });
|
|
33
32
|
server.node.server.on("upgrade", (req, socket, head) => {
|
|
34
33
|
handleUpgrade(
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import "#nitro
|
|
1
|
+
import "#nitro/virtual/polyfills";
|
|
2
2
|
import { toNodeHandler } from "srvx/node";
|
|
3
3
|
import wsAdapter from "crossws/adapters/node";
|
|
4
4
|
import { useNitroApp } from "nitro/app";
|
|
5
|
-
import { startScheduleRunner } from "nitro
|
|
6
|
-
import { resolveWebsocketHooks } from "nitro
|
|
7
|
-
import { hasWebSocket } from "#nitro-internal-virtual/feature-flags";
|
|
5
|
+
import { startScheduleRunner } from "#nitro/runtime/task";
|
|
6
|
+
import { resolveWebsocketHooks } from "#nitro/runtime/app";
|
|
8
7
|
const nitroApp = useNitroApp();
|
|
9
8
|
export const middleware = toNodeHandler(nitroApp.fetch);
|
|
10
|
-
const ws =
|
|
9
|
+
const ws = import.meta._websocket ? wsAdapter({ resolve: resolveWebsocketHooks }) : undefined;
|
|
11
10
|
export const handleUpgrade = ws?.handleUpgrade;
|
|
12
11
|
// Scheduled tasks
|
|
13
12
|
if (import.meta._tasks) {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import "#nitro
|
|
1
|
+
import "#nitro/virtual/polyfills";
|
|
2
2
|
import { NodeRequest, serve } from "srvx/node";
|
|
3
3
|
import wsAdapter from "crossws/adapters/node";
|
|
4
4
|
import { useNitroApp } from "nitro/app";
|
|
5
|
-
import { startScheduleRunner } from "nitro
|
|
6
|
-
import { trapUnhandledErrors } from "nitro
|
|
7
|
-
import { resolveWebsocketHooks } from "nitro
|
|
8
|
-
import { hasWebSocket } from "#nitro-internal-virtual/feature-flags";
|
|
5
|
+
import { startScheduleRunner } from "#nitro/runtime/task";
|
|
6
|
+
import { trapUnhandledErrors } from "#nitro/runtime/error/hooks";
|
|
7
|
+
import { resolveWebsocketHooks } from "#nitro/runtime/app";
|
|
9
8
|
const port = Number.parseInt(process.env.NITRO_PORT || process.env.PORT || "") || 3e3;
|
|
10
9
|
const host = process.env.NITRO_HOST || process.env.HOST;
|
|
11
10
|
const cert = process.env.NITRO_SSL_CERT;
|
|
@@ -21,7 +20,7 @@ const server = serve({
|
|
|
21
20
|
} : undefined,
|
|
22
21
|
fetch: nitroApp.fetch
|
|
23
22
|
});
|
|
24
|
-
if (
|
|
23
|
+
if (import.meta._websocket) {
|
|
25
24
|
const { handleUpgrade } = wsAdapter({ resolve: resolveWebsocketHooks });
|
|
26
25
|
server.node.server.on("upgrade", (req, socket, head) => {
|
|
27
26
|
handleUpgrade(
|
|
@@ -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,23 @@
|
|
|
1
|
-
import "#nitro
|
|
1
|
+
import "#nitro/virtual/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
|
+
// https://vercel.com/docs/headers/request-headers#x-forwarded-for
|
|
9
|
+
// srvx node adapter uses req.socket.remoteAddress for req.ip
|
|
10
|
+
let ip;
|
|
11
|
+
Object.defineProperty(req.socket, "remoteAddress", { get() {
|
|
12
|
+
const h = req.headers["x-forwarded-for"];
|
|
13
|
+
return ip ??= h?.split?.(",").shift()?.trim();
|
|
14
|
+
} });
|
|
15
|
+
// ISR route rewrite
|
|
16
|
+
const isrURL = isrRouteRewrite(req.url, req.headers["x-now-route-matches"]);
|
|
17
|
+
if (isrURL) {
|
|
18
|
+
const { routeRules } = getRouteRules("", isrURL[0]);
|
|
19
|
+
if (routeRules?.isr) {
|
|
20
|
+
req.url = isrURL[0] + (isrURL[1] ? `?${isrURL[1]}` : "");
|
|
12
21
|
}
|
|
13
22
|
}
|
|
14
23
|
return handler(req, res);
|
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
import "#nitro
|
|
2
|
-
import { useNitroApp } from "nitro/app";
|
|
1
|
+
import "#nitro/virtual/polyfills";
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
req.runtime = {
|
|
15
|
+
name: "vercel",
|
|
16
|
+
vercel: { context }
|
|
17
|
+
};
|
|
18
|
+
let ip;
|
|
19
|
+
Object.defineProperty(req, "ip", { get() {
|
|
20
|
+
const h = req.headers.get("x-forwarded-for");
|
|
21
|
+
return ip ??= h?.split(",").shift()?.trim();
|
|
22
|
+
} });
|
|
18
23
|
req.waitUntil = context?.waitUntil;
|
|
19
24
|
return nitroApp.fetch(req);
|
|
20
25
|
} };
|
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,12 +1,16 @@
|
|
|
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
|
-
var __nitro__: NitroApp | undefined;
|
|
6
|
+
var __nitro__: Partial<Record<"default" | "prerender" | (string & {}), NitroApp | undefined>> | undefined;
|
|
7
7
|
}
|
|
8
8
|
export declare function useNitroApp(): NitroApp;
|
|
9
9
|
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
|
+
};
|
|
@@ -2,12 +2,23 @@ import { H3Core, toRequest } from "h3";
|
|
|
2
2
|
import { HookableCore } from "hookable";
|
|
3
3
|
import { nitroAsyncContext } from "./context.mjs";
|
|
4
4
|
// IMPORTANT: virtual imports and user code should be imported last to avoid initialization order issues
|
|
5
|
-
import errorHandler from "#nitro
|
|
6
|
-
import { plugins } from "#nitro
|
|
7
|
-
import { findRoute, findRouteRules, globalMiddleware, findRoutedMiddleware } from "#nitro
|
|
8
|
-
import { hasRouteRules, hasRoutedMiddleware, hasGlobalMiddleware, hasRoutes, hasHooks, hasPlugins } from "#nitro
|
|
5
|
+
import errorHandler from "#nitro/virtual/error-handler";
|
|
6
|
+
import { plugins } from "#nitro/virtual/plugins";
|
|
7
|
+
import { findRoute, findRouteRules, globalMiddleware, findRoutedMiddleware } from "#nitro/virtual/routing";
|
|
8
|
+
import { hasRouteRules, hasRoutedMiddleware, hasGlobalMiddleware, hasRoutes, hasHooks, hasPlugins } from "#nitro/virtual/feature-flags";
|
|
9
|
+
const APP_ID = import.meta.prerender ? "prerender" : "default";
|
|
9
10
|
export function useNitroApp() {
|
|
10
|
-
|
|
11
|
+
let instance = useNitroApp._instance;
|
|
12
|
+
if (instance) {
|
|
13
|
+
return instance;
|
|
14
|
+
}
|
|
15
|
+
instance = useNitroApp._instance = createNitroApp();
|
|
16
|
+
globalThis.__nitro__ = globalThis.__nitro__ || {};
|
|
17
|
+
globalThis.__nitro__[APP_ID] = instance;
|
|
18
|
+
if (hasPlugins) {
|
|
19
|
+
initNitroPlugins(instance);
|
|
20
|
+
}
|
|
21
|
+
return instance;
|
|
11
22
|
}
|
|
12
23
|
export function useNitroHooks() {
|
|
13
24
|
const nitroApp = useNitroApp();
|
|
@@ -42,21 +53,6 @@ export function fetch(resource, init, context) {
|
|
|
42
53
|
resource = resource._request || resource;
|
|
43
54
|
return fetch(resource, init);
|
|
44
55
|
}
|
|
45
|
-
function initNitroApp() {
|
|
46
|
-
const nitroApp = createNitroApp();
|
|
47
|
-
if (hasPlugins) {
|
|
48
|
-
for (const plugin of plugins) {
|
|
49
|
-
try {
|
|
50
|
-
plugin(nitroApp);
|
|
51
|
-
} catch (error) {
|
|
52
|
-
nitroApp.captureError?.(error, { tags: ["plugin"] });
|
|
53
|
-
throw error;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
globalThis.__nitro__ = nitroApp;
|
|
58
|
-
return nitroApp;
|
|
59
|
-
}
|
|
60
56
|
function createNitroApp() {
|
|
61
57
|
const hooks = hasHooks ? new HookableCore() : undefined;
|
|
62
58
|
const captureError = (error, errorCtx) => {
|
|
@@ -71,7 +67,7 @@ function createNitroApp() {
|
|
|
71
67
|
context: errorCtx
|
|
72
68
|
});
|
|
73
69
|
}
|
|
74
|
-
if (hasHooks && typeof errorCtx.event.req.waitUntil === "function") {
|
|
70
|
+
if (hasHooks && promise && typeof errorCtx.event.req.waitUntil === "function") {
|
|
75
71
|
errorCtx.event.req.waitUntil(promise);
|
|
76
72
|
}
|
|
77
73
|
}
|
|
@@ -119,6 +115,17 @@ function createNitroApp() {
|
|
|
119
115
|
};
|
|
120
116
|
return app;
|
|
121
117
|
}
|
|
118
|
+
function initNitroPlugins(app) {
|
|
119
|
+
for (const plugin of plugins) {
|
|
120
|
+
try {
|
|
121
|
+
plugin(app);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
app.captureError?.(error, { tags: ["plugin"] });
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return app;
|
|
128
|
+
}
|
|
122
129
|
function createH3App(config) {
|
|
123
130
|
// Create H3 app
|
|
124
131
|
const h3App = new H3Core(config);
|
|
@@ -148,7 +155,7 @@ function createH3App(config) {
|
|
|
148
155
|
}
|
|
149
156
|
return h3App;
|
|
150
157
|
}
|
|
151
|
-
function getRouteRules(method, pathname) {
|
|
158
|
+
export function getRouteRules(method, pathname) {
|
|
152
159
|
const m = findRouteRules(method, pathname);
|
|
153
160
|
if (!m?.length) {
|
|
154
161
|
return { routeRuleMiddleware: [] };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createDatabase } from "db0";
|
|
2
|
-
import { connectionConfigs } from "#nitro
|
|
2
|
+
import { connectionConfigs } from "#nitro/virtual/database";
|
|
3
3
|
const instances = Object.create(null);
|
|
4
4
|
export function useDatabase(name = "default") {
|
|
5
5
|
if (instances[name]) {
|
|
@@ -44,7 +44,7 @@ export async function defaultHandler(error, event, opts) {
|
|
|
44
44
|
consola.error(`[request error] ${tags} [${event.req.method}] ${url}\n\n`, ansiError);
|
|
45
45
|
}
|
|
46
46
|
// Use HTML response only when user-agent expects it (browsers)
|
|
47
|
-
const useJSON = opts?.json
|
|
47
|
+
const useJSON = opts?.json ?? !event.req.headers.get("accept")?.includes("text/html");
|
|
48
48
|
// Prepare headers
|
|
49
49
|
const headers = {
|
|
50
50
|
"content-type": useJSON ? "application/json" : "text/html",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { H3 } from "h3";
|
|
2
2
|
import { runTask } from "../task.mjs";
|
|
3
|
-
import { scheduledTasks, tasks } from "#nitro
|
|
3
|
+
import { scheduledTasks, tasks } from "#nitro/virtual/tasks";
|
|
4
4
|
export default new H3().get("/_nitro/tasks", async () => {
|
|
5
5
|
const _tasks = await Promise.all(Object.entries(tasks).map(async ([name, task]) => {
|
|
6
6
|
const _task = await task.resolve?.();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineHandler, getRequestURL } from "h3";
|
|
2
2
|
import { joinURL } from "ufo";
|
|
3
3
|
import { defu } from "defu";
|
|
4
|
-
import { handlersMeta } from "#nitro
|
|
4
|
+
import { handlersMeta } from "#nitro/virtual/routing-meta";
|
|
5
5
|
import { useRuntimeConfig } from "../runtime-config.mjs";
|
|
6
6
|
// Served as /_openapi.json
|
|
7
7
|
export default defineHandler((event) => {
|
|
@@ -12,7 +12,7 @@ export default defineHandler((event) => {
|
|
|
12
12
|
title: "Nitro Server Routes",
|
|
13
13
|
...runtimeConfig.nitro?.openAPI?.meta
|
|
14
14
|
};
|
|
15
|
-
const { paths, globals: { components
|
|
15
|
+
const { paths, globals: { components, ...globalsRest } } = getHandlersMeta();
|
|
16
16
|
const extensible = Object.fromEntries(Object.entries(globalsRest).filter(([key]) => key.startsWith("x-")));
|
|
17
17
|
return {
|
|
18
18
|
openapi: "3.1.0",
|
|
@@ -38,7 +38,7 @@ function getHandlersMeta() {
|
|
|
38
38
|
const { route, parameters } = normalizeRoute(h.route || "");
|
|
39
39
|
const tags = defaultTags(h.route || "");
|
|
40
40
|
const method = (h.method || "get").toLowerCase();
|
|
41
|
-
const { $global
|
|
41
|
+
const { $global, ...openAPI } = h.meta?.openAPI || {};
|
|
42
42
|
const item = { [method]: {
|
|
43
43
|
tags,
|
|
44
44
|
parameters,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { serverFetch } from "../app.mjs";
|
|
2
|
-
import { rendererTemplate, rendererTemplateFile, isStaticTemplate } from "#nitro
|
|
2
|
+
import { rendererTemplate, rendererTemplateFile, isStaticTemplate } from "#nitro/virtual/renderer-template";
|
|
3
3
|
import { HTTPResponse } from "h3";
|
|
4
4
|
import { hasTemplateSyntax, renderToResponse, compileTemplate } from "rendu";
|
|
5
5
|
export default async function renderIndexHTML(event) {
|
|
@@ -3,11 +3,11 @@ import { useRuntimeConfig } from "../runtime-config.mjs";
|
|
|
3
3
|
// Served as /_scalar
|
|
4
4
|
export default defineHandler((event) => {
|
|
5
5
|
const runtimeConfig = useRuntimeConfig();
|
|
6
|
-
const title = runtimeConfig.nitro
|
|
7
|
-
const description = runtimeConfig.nitro
|
|
8
|
-
const openAPIEndpoint = runtimeConfig.nitro
|
|
6
|
+
const title = runtimeConfig.nitro?.openAPI?.meta?.title || "API Reference";
|
|
7
|
+
const description = runtimeConfig.nitro?.openAPI?.meta?.description || "";
|
|
8
|
+
const openAPIEndpoint = runtimeConfig.nitro?.openAPI?.route || "./_openapi.json";
|
|
9
9
|
// https://github.com/scalar/scalar
|
|
10
|
-
const _config = runtimeConfig.nitro
|
|
10
|
+
const _config = runtimeConfig.nitro?.openAPI?.ui?.scalar;
|
|
11
11
|
const scalarConfig = {
|
|
12
12
|
..._config,
|
|
13
13
|
url: openAPIEndpoint,
|
|
@@ -3,9 +3,9 @@ import { useRuntimeConfig } from "../runtime-config.mjs";
|
|
|
3
3
|
// https://github.com/swagger-api/swagger-ui
|
|
4
4
|
export default defineHandler((event) => {
|
|
5
5
|
const runtimeConfig = useRuntimeConfig();
|
|
6
|
-
const title = runtimeConfig.nitro
|
|
7
|
-
const description = runtimeConfig.nitro
|
|
8
|
-
const openAPIEndpoint = runtimeConfig.nitro
|
|
6
|
+
const title = runtimeConfig.nitro?.openAPI?.meta?.title || "API Reference";
|
|
7
|
+
const description = runtimeConfig.nitro?.openAPI?.meta?.description || "";
|
|
8
|
+
const openAPIEndpoint = runtimeConfig.nitro?.openAPI?.route || "./_openapi.json";
|
|
9
9
|
const CDN_BASE = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@^5";
|
|
10
10
|
event.res.headers.set("Content-Type", "text/html");
|
|
11
11
|
return `<!doctype html>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { runtimeConfig } from "#nitro-internal-virtual/runtime-config";
|
|
2
1
|
import { snakeCase } from "scule";
|
|
2
|
+
import { runtimeConfig } from "#nitro/virtual/runtime-config";
|
|
3
3
|
export function useRuntimeConfig() {
|
|
4
4
|
return useRuntimeConfig._cached ||= getRuntimeConfig();
|
|
5
5
|
}
|
|
@@ -12,13 +12,6 @@ function getRuntimeConfig() {
|
|
|
12
12
|
});
|
|
13
13
|
return runtimeConfig;
|
|
14
14
|
}
|
|
15
|
-
function getEnv(key, opts) {
|
|
16
|
-
const envKey = snakeCase(key).toUpperCase();
|
|
17
|
-
return process.env[opts.prefix + envKey] ?? process.env[opts.altPrefix + envKey];
|
|
18
|
-
}
|
|
19
|
-
function _isObject(input) {
|
|
20
|
-
return typeof input === "object" && !Array.isArray(input);
|
|
21
|
-
}
|
|
22
15
|
export function applyEnv(obj, opts, parentKey = "") {
|
|
23
16
|
for (const key in obj) {
|
|
24
17
|
const subKey = parentKey ? `${parentKey}_${key}` : key;
|
|
@@ -52,3 +45,10 @@ function _expandFromEnv(value) {
|
|
|
52
45
|
return process.env[key] || match;
|
|
53
46
|
});
|
|
54
47
|
}
|
|
48
|
+
function getEnv(key, opts) {
|
|
49
|
+
const envKey = snakeCase(key).toUpperCase();
|
|
50
|
+
return process.env[opts.prefix + envKey] ?? process.env[opts.altPrefix + envKey];
|
|
51
|
+
}
|
|
52
|
+
function _isObject(input) {
|
|
53
|
+
return input !== null && typeof input === "object" && !Array.isArray(input);
|
|
54
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HTTPError, defineHandler } from "h3";
|
|
2
2
|
import { decodePath, joinURL, withLeadingSlash, withoutTrailingSlash } from "ufo";
|
|
3
|
-
import { getAsset, isPublicAssetURL, readAsset } from "#nitro
|
|
3
|
+
import { getAsset, isPublicAssetURL, readAsset } from "#nitro/virtual/public-assets";
|
|
4
4
|
const METHODS = new Set(["HEAD", "GET"]);
|
|
5
5
|
const EncodingMap = {
|
|
6
6
|
gzip: ".gz",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { prefixStorage } from "unstorage";
|
|
2
|
-
import { initStorage } from "#nitro
|
|
2
|
+
import { initStorage } from "#nitro/virtual/storage";
|
|
3
3
|
export function useStorage(base = "") {
|
|
4
4
|
const storage = useStorage._storage ??= initStorage();
|
|
5
5
|
return base ? prefixStorage(storage, base) : storage;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cron } from "croner";
|
|
2
2
|
import { HTTPError } from "h3";
|
|
3
|
-
import { scheduledTasks, tasks } from "#nitro
|
|
3
|
+
import { scheduledTasks, tasks } from "#nitro/virtual/tasks";
|
|
4
4
|
/** @experimental */
|
|
5
5
|
export function defineTask(def) {
|
|
6
6
|
if (typeof def.run !== "function") {
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import "#nitro
|
|
1
|
+
import "#nitro/virtual/polyfills";
|
|
2
2
|
import wsAdapter from "crossws/adapters/node";
|
|
3
3
|
|
|
4
4
|
import { useNitroApp } from "nitro/app";
|
|
5
|
-
import { resolveWebsocketHooks } from "nitro
|
|
6
|
-
import { hasWebSocket } from "#nitro-internal-virtual/feature-flags";
|
|
5
|
+
import { resolveWebsocketHooks } from "#nitro/runtime/app";
|
|
7
6
|
|
|
8
7
|
const nitroApp = useNitroApp();
|
|
9
8
|
|
|
10
9
|
export const fetch = nitroApp.fetch;
|
|
11
10
|
|
|
12
|
-
const ws =
|
|
11
|
+
const ws = import.meta._websocket
|
|
13
12
|
? wsAdapter({ resolve: resolveWebsocketHooks })
|
|
14
13
|
: undefined;
|
|
15
14
|
|