nitro 3.0.1-alpha.2 → 3.0.260311-beta
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/LICENSE +6 -0
- package/README.md +2 -2
- package/dist/THIRD-PARTY-LICENSES.md +1646 -0
- package/dist/_build/common.mjs +6977 -2556
- package/dist/_build/rolldown.mjs +32 -31
- package/dist/_build/rollup.mjs +28 -35
- package/dist/_build/vite.build.mjs +10 -8
- package/dist/_chunks/nitro.mjs +80 -112
- package/dist/_chunks/nitro2.mjs +8 -7
- package/dist/_chunks/nitro3.mjs +129 -0
- package/dist/_chunks/utils.mjs +42 -24
- package/dist/_common.mjs +14 -24
- package/dist/{_chunks/dev.mjs → _dev.mjs} +132 -320
- package/dist/_libs/_.mjs +3 -0
- package/dist/_libs/_2.mjs +2 -0
- package/dist/_libs/_3.mjs +3 -0
- package/dist/_libs/_4.mjs +2 -0
- package/dist/_libs/_5.mjs +3 -0
- package/dist/_libs/_6.mjs +4 -0
- package/dist/_libs/_7.mjs +5 -0
- package/dist/_libs/c12+rc9.mjs +812 -0
- package/dist/_libs/{c12+giget+readdirp+chokidar.d.mts → c12+readdirp+chokidar.d.mts} +52 -36
- package/dist/_libs/citty.mjs +10 -12
- package/dist/_libs/commondir+is-reference.mjs +60 -49
- package/dist/_libs/compatx.mjs +1 -2
- package/dist/_libs/esbuild.d.mts +1 -1
- package/dist/_libs/escape-string-regexp.mjs +1 -2
- package/dist/_libs/{pluginutils+plugin-commonjs.d.mts → estree+pluginutils.d.mts} +2 -2
- package/dist/_libs/estree-walker.mjs +1 -4
- package/dist/_libs/exsolve.d.mts +1 -0
- package/dist/_libs/hasown+resolve+deepmerge.mjs +146 -169
- package/dist/_libs/httpxy.d.mts +12 -9
- package/dist/_libs/httpxy.mjs +299 -43
- package/dist/_libs/js-tokens.d.mts +1 -0
- package/dist/_libs/klona.mjs +1 -2
- package/dist/_libs/mlly.d.mts +1 -1
- package/dist/_libs/nypm+tinyexec.mjs +845 -0
- package/dist/_libs/perfect-debounce.mjs +88 -0
- package/dist/_libs/plugin-alias.mjs +2 -4
- package/dist/_libs/plugin-inject.mjs +2 -6
- package/dist/_libs/plugin-json.mjs +2 -4
- package/dist/_libs/pluginutils.mjs +5 -11
- package/dist/_libs/readdirp+chokidar.mjs +187 -192
- package/dist/_libs/remapping.mjs +1 -3
- package/dist/_libs/resolve-uri+gen-mapping.mjs +15 -21
- package/dist/_libs/rou3.d.mts +3 -2
- package/dist/_libs/rou3.mjs +225 -51
- package/dist/_libs/std-env.d.mts +10 -2
- package/dist/_libs/strip-literal.d.mts +1 -0
- package/dist/_libs/tsconfck.mjs +21 -40
- package/dist/_libs/ultrahtml.mjs +3 -14
- package/dist/_libs/unimport+unplugin.mjs +250 -351
- package/dist/_libs/unplugin+unimport.d.mts +7 -10
- package/dist/_presets.mjs +389 -432
- package/dist/builder.d.mts +5 -4
- package/dist/builder.mjs +12 -6
- package/dist/cli/_chunks/build.mjs +22 -23
- package/dist/cli/_chunks/common.mjs +1 -2
- package/dist/cli/_chunks/deploy.mjs +40 -0
- package/dist/cli/_chunks/dev.mjs +9 -9
- package/dist/cli/_chunks/docs.mjs +30 -0
- package/dist/cli/_chunks/list.mjs +4 -6
- package/dist/cli/_chunks/prepare.mjs +2 -4
- package/dist/cli/_chunks/preview.mjs +51 -0
- package/dist/cli/_chunks/run.mjs +7 -9
- package/dist/cli/_chunks/task.mjs +1 -3
- package/dist/cli/index.mjs +5 -4
- package/dist/node_modules/@poppinss/dumper/build/formatters/html/main.js +8 -0
- package/dist/node_modules/@poppinss/dumper/package.json +1 -1
- package/dist/node_modules/croner/dist/croner.js +1 -1
- package/dist/node_modules/croner/package.json +11 -1
- package/dist/node_modules/youch/build/helpers-B9BQYaS6.js +23 -0
- package/dist/node_modules/youch/build/index.js +204 -351
- package/dist/node_modules/youch/build/public/error_info/script.js +1 -1
- package/dist/node_modules/youch/build/public_dir-C5bujZKB.js +25 -0
- package/dist/node_modules/youch/build/src/templates/error_cause/main.js +44 -0
- package/dist/node_modules/youch/build/src/templates/error_info/main.js +72 -0
- package/dist/node_modules/youch/build/src/templates/error_metadata/main.js +65 -0
- package/dist/node_modules/youch/build/src/templates/error_stack/main.js +152 -0
- package/dist/node_modules/youch/build/src/templates/error_stack_source/main.js +46 -0
- package/dist/node_modules/youch/build/src/templates/header/main.js +24 -0
- package/dist/node_modules/youch/build/src/templates/layout/main.js +27 -0
- package/dist/node_modules/youch/package.json +34 -31
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +9 -56
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +1 -0
- package/dist/presets/_nitro/runtime/service-worker.mjs +0 -1
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +3 -1
- package/dist/presets/bun/runtime/bun.mjs +4 -3
- package/dist/presets/deno/runtime/deno-server.mjs +4 -3
- package/dist/presets/netlify/runtime/netlify-edge.mjs +0 -1
- package/dist/presets/netlify/runtime/netlify.mjs +1 -1
- package/dist/presets/node/runtime/node-cluster.mjs +3 -2
- package/dist/presets/node/runtime/node-server.mjs +3 -2
- package/dist/presets/stormkit/runtime/stormkit.mjs +0 -1
- package/dist/presets/vercel/runtime/cron-handler.mjs +25 -0
- package/dist/presets/vercel/runtime/vercel.web.mjs +2 -4
- package/dist/presets/zephyr/runtime/server.mjs +3 -0
- package/dist/runtime/internal/cache.d.mts +0 -4
- package/dist/runtime/internal/cache.mjs +32 -256
- package/dist/runtime/internal/context.d.mts +3 -1
- package/dist/runtime/internal/error/dev.d.mts +5 -4
- package/dist/runtime/internal/error/dev.mjs +38 -40
- package/dist/runtime/internal/error/hooks.d.mts +1 -1
- package/dist/runtime/internal/error/prod.d.mts +2 -5
- package/dist/runtime/internal/error/prod.mjs +19 -33
- package/dist/runtime/internal/error/utils.d.mts +4 -4
- package/dist/runtime/internal/meta.d.mts +1 -1
- package/dist/runtime/internal/plugin.d.mts +2 -2
- package/dist/runtime/internal/route-rules.d.mts +9 -4
- package/dist/runtime/internal/route-rules.mjs +9 -1
- package/dist/runtime/internal/routes/dev-tasks.d.mts +3 -2
- package/dist/runtime/internal/routes/dev-tasks.mjs +6 -2
- package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
- package/dist/runtime/internal/routes/renderer-template.dev.d.mts +2 -1
- package/dist/runtime/internal/runtime-config.d.mts +1 -1
- package/dist/runtime/internal/static.mjs +5 -4
- package/dist/runtime/internal/task.d.mts +3 -1
- package/dist/runtime/internal/task.mjs +2 -2
- package/dist/runtime/internal/vite/dev-entry.mjs +6 -3
- package/dist/runtime/internal/vite/dev-worker.mjs +264 -0
- package/dist/runtime/meta.mjs +1 -0
- package/dist/runtime/nitro.d.mts +2 -0
- package/dist/runtime/nitro.mjs +2 -0
- package/dist/runtime/virtual/error-handler.mjs +1 -1
- package/dist/runtime/virtual/server-assets.d.mts +2 -1
- package/dist/runtime/vite.d.mts +1 -1
- package/dist/types/index.d.mts +68 -117
- package/dist/types/index.mjs +1 -11
- package/dist/vite.d.mts +3 -3
- package/dist/vite.mjs +236 -233
- package/package.json +83 -68
- package/skills/nitro/SKILL.md +10 -0
- package/skills/nitro/docs/TOC.md +83 -0
- package/skills/nitro/docs/_navigation.json +679 -0
- package/skills/nitro/docs/config/index.md +1147 -0
- package/skills/nitro/docs/deploy/index.md +64 -0
- package/skills/nitro/docs/deploy/providers/alwaysdata.md +50 -0
- package/skills/nitro/docs/deploy/providers/aws-amplify.md +81 -0
- package/skills/nitro/docs/deploy/providers/aws.md +47 -0
- package/skills/nitro/docs/deploy/providers/azure.md +72 -0
- package/skills/nitro/docs/deploy/providers/cleavr.md +33 -0
- package/skills/nitro/docs/deploy/providers/cloudflare.md +375 -0
- package/skills/nitro/docs/deploy/providers/deno-deploy.md +66 -0
- package/skills/nitro/docs/deploy/providers/digitalocean.md +46 -0
- package/skills/nitro/docs/deploy/providers/firebase.md +32 -0
- package/skills/nitro/docs/deploy/providers/flightcontrol.md +67 -0
- package/skills/nitro/docs/deploy/providers/genezio.md +67 -0
- package/skills/nitro/docs/deploy/providers/github-pages.md +68 -0
- package/skills/nitro/docs/deploy/providers/gitlab-pages.md +37 -0
- package/skills/nitro/docs/deploy/providers/heroku.md +84 -0
- package/skills/nitro/docs/deploy/providers/iis.md +38 -0
- package/skills/nitro/docs/deploy/providers/koyeb.md +109 -0
- package/skills/nitro/docs/deploy/providers/netlify.md +47 -0
- package/skills/nitro/docs/deploy/providers/platform-sh.md +37 -0
- package/skills/nitro/docs/deploy/providers/render.md +37 -0
- package/skills/nitro/docs/deploy/providers/stormkit.md +24 -0
- package/skills/nitro/docs/deploy/providers/vercel.md +179 -0
- package/skills/nitro/docs/deploy/providers/zeabur.md +19 -0
- package/skills/nitro/docs/deploy/providers/zephyr.md +99 -0
- package/skills/nitro/docs/deploy/providers/zerops.md +102 -0
- package/skills/nitro/docs/deploy/runtimes/bun.md +15 -0
- package/skills/nitro/docs/deploy/runtimes/deno.md +19 -0
- package/skills/nitro/docs/deploy/runtimes/node.md +63 -0
- package/skills/nitro/docs/docs/assets.md +166 -0
- package/skills/nitro/docs/docs/cache.md +408 -0
- package/skills/nitro/docs/docs/configuration.md +256 -0
- package/skills/nitro/docs/docs/database.md +185 -0
- package/skills/nitro/docs/docs/index.md +56 -0
- package/skills/nitro/docs/docs/lifecycle.md +204 -0
- package/skills/nitro/docs/docs/migration.md +215 -0
- package/skills/nitro/docs/docs/nightly.md +31 -0
- package/skills/nitro/docs/docs/plugins.md +164 -0
- package/skills/nitro/docs/docs/quick-start.md +110 -0
- package/skills/nitro/docs/docs/renderer.md +322 -0
- package/skills/nitro/docs/docs/routing.md +711 -0
- package/skills/nitro/docs/docs/server-entry.md +239 -0
- package/skills/nitro/docs/docs/storage.md +261 -0
- package/skills/nitro/docs/docs/tasks.md +277 -0
- package/skills/nitro/docs/examples/api-routes.md +145 -0
- package/skills/nitro/docs/examples/auto-imports.md +93 -0
- package/skills/nitro/docs/examples/cached-handler.md +81 -0
- package/skills/nitro/docs/examples/custom-error-handler.md +98 -0
- package/skills/nitro/docs/examples/database.md +157 -0
- package/skills/nitro/docs/examples/elysia.md +70 -0
- package/skills/nitro/docs/examples/express.md +78 -0
- package/skills/nitro/docs/examples/fastify.md +79 -0
- package/skills/nitro/docs/examples/hello-world.md +68 -0
- package/skills/nitro/docs/examples/hono.md +74 -0
- package/skills/nitro/docs/examples/import-alias.md +100 -0
- package/skills/nitro/docs/examples/index.md +3 -0
- package/skills/nitro/docs/examples/middleware.md +91 -0
- package/skills/nitro/docs/examples/mono-jsx.md +68 -0
- package/skills/nitro/docs/examples/nano-jsx.md +70 -0
- package/skills/nitro/docs/examples/plugins.md +91 -0
- package/skills/nitro/docs/examples/renderer.md +113 -0
- package/skills/nitro/docs/examples/runtime-config.md +97 -0
- package/skills/nitro/docs/examples/server-fetch.md +87 -0
- package/skills/nitro/docs/examples/shiki.md +198 -0
- package/skills/nitro/docs/examples/virtual-routes.md +74 -0
- package/skills/nitro/docs/examples/vite-nitro-plugin.md +79 -0
- package/skills/nitro/docs/examples/vite-rsc.md +1041 -0
- package/skills/nitro/docs/examples/vite-ssr-html.md +217 -0
- package/skills/nitro/docs/examples/vite-ssr-preact.md +247 -0
- package/skills/nitro/docs/examples/vite-ssr-react.md +226 -0
- package/skills/nitro/docs/examples/vite-ssr-solid.md +256 -0
- package/skills/nitro/docs/examples/vite-ssr-tsr-react.md +442 -0
- package/skills/nitro/docs/examples/vite-ssr-tss-react.md +444 -0
- package/skills/nitro/docs/examples/vite-ssr-vue-router.md +616 -0
- package/skills/nitro/docs/examples/vite-trpc.md +335 -0
- package/skills/nitro/docs/examples/websocket.md +282 -0
- package/skills/nitro/docs/index.md +121 -0
- package/dist/_libs/confbox.mjs +0 -2509
- package/dist/_libs/nypm+giget+tinyexec.mjs +0 -3603
- package/dist/_libs/rc9+c12+dotenv.mjs +0 -972
- package/dist/node_modules/hookable/dist/index.mjs +0 -266
- package/dist/node_modules/hookable/package.json +0 -52
- package/dist/node_modules/youch/build/chunk-4L7RY2JA.js +0 -42
- package/dist/node_modules/youch/build/chunk-7QV3D5YX.js +0 -83
- package/dist/node_modules/youch/build/chunk-AUGPHE32.js +0 -39
- package/dist/node_modules/youch/build/chunk-CM7DWJNZ.js +0 -44
- package/dist/node_modules/youch/build/chunk-EJH674NB.js +0 -223
- package/dist/node_modules/youch/build/chunk-OIJ3WD7L.js +0 -81
- package/dist/node_modules/youch/build/chunk-P36L72PL.js +0 -87
- package/dist/node_modules/youch/build/chunk-PE3GG3TN.js +0 -65
- package/dist/node_modules/youch/build/chunk-X53OIOJH.js +0 -70
- package/dist/presets/_nitro/runtime/nitro-dev.d.mts +0 -2
- package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +0 -3
- package/dist/presets/_nitro/runtime/service-worker.d.mts +0 -2
- package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +0 -2
- package/dist/presets/aws-lambda/runtime/_utils.d.mts +0 -8
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +0 -2
- package/dist/presets/aws-lambda/runtime/aws-lambda.d.mts +0 -3
- package/dist/presets/azure/runtime/_utils.d.mts +0 -2
- package/dist/presets/azure/runtime/azure-swa.d.mts +0 -5
- package/dist/presets/bun/runtime/bun.d.mts +0 -3
- package/dist/presets/cloudflare/runtime/_module-handler.d.mts +0 -16
- package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +0 -11
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +0 -3
- package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +0 -20
- package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +0 -3
- package/dist/presets/deno/runtime/deno-deploy.d.mts +0 -5
- package/dist/presets/deno/runtime/deno-server.d.mts +0 -3
- package/dist/presets/netlify/runtime/netlify-edge.d.mts +0 -3
- package/dist/presets/netlify/runtime/netlify.d.mts +0 -4
- package/dist/presets/node/runtime/node-cluster.d.mts +0 -3
- package/dist/presets/node/runtime/node-middleware.d.mts +0 -3
- package/dist/presets/node/runtime/node-server.d.mts +0 -3
- package/dist/presets/standard/runtime/server.d.mts +0 -3
- package/dist/presets/stormkit/runtime/stormkit.d.mts +0 -21
- package/dist/presets/vercel/runtime/isr.d.mts +0 -2
- package/dist/presets/vercel/runtime/vercel.node.d.mts +0 -3
- package/dist/presets/vercel/runtime/vercel.web.d.mts +0 -8
- package/dist/presets/winterjs/runtime/winterjs.d.mts +0 -2
- package/dist/presets/zeabur/runtime/zeabur.d.mts +0 -3
- package/dist/runtime/internal/vite/node-runner.mjs +0 -359
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { NitroErrorHandler } from "nitro/types";
|
|
2
2
|
export declare function defineNitroErrorHandler(handler: NitroErrorHandler): NitroErrorHandler;
|
|
3
3
|
export type InternalHandlerResponse = {
|
|
4
|
-
status
|
|
5
|
-
statusText
|
|
6
|
-
headers
|
|
7
|
-
body
|
|
4
|
+
status?: number;
|
|
5
|
+
statusText?: string | undefined;
|
|
6
|
+
headers?: HeadersInit;
|
|
7
|
+
body?: string | Record<string, any>;
|
|
8
8
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { NitroRouteMeta } from "nitro/types";
|
|
2
|
-
export declare function defineRouteMeta(meta: NitroRouteMeta);
|
|
2
|
+
export declare function defineRouteMeta(meta: NitroRouteMeta): NitroRouteMeta;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { NitroAppPlugin } from "nitro/types";
|
|
2
|
-
export declare function defineNitroPlugin(def: NitroAppPlugin);
|
|
3
|
-
export declare const nitroPlugin:
|
|
2
|
+
export declare function defineNitroPlugin(def: NitroAppPlugin): NitroAppPlugin;
|
|
3
|
+
export declare const nitroPlugin: (def: NitroAppPlugin) => NitroAppPlugin;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare const
|
|
1
|
+
import type { Middleware } from "h3";
|
|
2
|
+
import type { MatchedRouteRule, NitroRouteRules } from "nitro/types";
|
|
3
|
+
type RouteRuleCtor<T extends keyof NitroRouteRules> = (m: MatchedRouteRule<T>) => Middleware;
|
|
4
|
+
export declare const headers: RouteRuleCtor<"headers">;
|
|
5
|
+
export declare const redirect: RouteRuleCtor<"redirect">;
|
|
6
|
+
export declare const proxy: RouteRuleCtor<"proxy">;
|
|
7
|
+
export declare const cache: RouteRuleCtor<"cache">;
|
|
8
|
+
export declare const basicAuth: RouteRuleCtor<"auth">;
|
|
9
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { proxyRequest, redirect as sendRedirect } from "h3";
|
|
1
|
+
import { proxyRequest, redirect as sendRedirect, requireBasicAuth } from "h3";
|
|
2
2
|
import { joinURL, withQuery, withoutBase } from "ufo";
|
|
3
3
|
import { defineCachedHandler } from "./cache.mjs";
|
|
4
4
|
// Headers route rule
|
|
@@ -62,3 +62,11 @@ export const cache = ((m) => function cacheRouteRule(event, next) {
|
|
|
62
62
|
}
|
|
63
63
|
return cachedHandler(event);
|
|
64
64
|
});
|
|
65
|
+
// basicAuth auth route rule
|
|
66
|
+
export const basicAuth = ((m) => async function authRouteRule(event, next) {
|
|
67
|
+
if (!m.options) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
await requireBasicAuth(event, m.options);
|
|
71
|
+
return next();
|
|
72
|
+
});
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { H3 } from "h3";
|
|
2
|
+
declare const app: H3;
|
|
3
|
+
export default app;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { H3 } from "h3";
|
|
2
2
|
import { runTask } from "../task.mjs";
|
|
3
3
|
import { scheduledTasks, tasks } from "#nitro/virtual/tasks";
|
|
4
|
-
|
|
4
|
+
const app = 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?.();
|
|
7
7
|
return [name, { description: _task?.meta?.description }];
|
|
@@ -17,5 +17,9 @@ export default new H3().get("/_nitro/tasks", async () => {
|
|
|
17
17
|
...Object.fromEntries(event.url.searchParams.entries()),
|
|
18
18
|
...body
|
|
19
19
|
};
|
|
20
|
-
return await runTask(name, {
|
|
20
|
+
return await runTask(name, {
|
|
21
|
+
context: { waitUntil: event.req.waitUntil },
|
|
22
|
+
payload
|
|
23
|
+
});
|
|
21
24
|
});
|
|
25
|
+
export default app;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { H3Event } from "h3";
|
|
2
|
-
export default function renderIndexHTML(event: H3Event);
|
|
2
|
+
export default function renderIndexHTML(event: H3Event): any;
|
|
@@ -5,5 +5,5 @@ type EnvOptions = {
|
|
|
5
5
|
altPrefix?: string;
|
|
6
6
|
envExpansion?: boolean;
|
|
7
7
|
};
|
|
8
|
-
export declare function applyEnv(obj: Record<string, any>, opts: EnvOptions, parentKey?: string)
|
|
8
|
+
export declare function applyEnv(obj: Record<string, any>, opts: EnvOptions, parentKey?: string): Record<string, any>;
|
|
9
9
|
export {};
|
|
@@ -4,7 +4,8 @@ import { getAsset, isPublicAssetURL, readAsset } from "#nitro/virtual/public-ass
|
|
|
4
4
|
const METHODS = new Set(["HEAD", "GET"]);
|
|
5
5
|
const EncodingMap = {
|
|
6
6
|
gzip: ".gz",
|
|
7
|
-
br: ".br"
|
|
7
|
+
br: ".br",
|
|
8
|
+
zstd: ".zst"
|
|
8
9
|
};
|
|
9
10
|
export default defineHandler((event) => {
|
|
10
11
|
if (event.req.method && !METHODS.has(event.req.method)) {
|
|
@@ -14,9 +15,6 @@ export default defineHandler((event) => {
|
|
|
14
15
|
let asset;
|
|
15
16
|
const encodingHeader = event.req.headers.get("accept-encoding") || "";
|
|
16
17
|
const encodings = [...encodingHeader.split(",").map((e) => EncodingMap[e.trim()]).filter(Boolean).sort(), ""];
|
|
17
|
-
if (encodings.length > 1) {
|
|
18
|
-
event.res.headers.append("Vary", "Accept-Encoding");
|
|
19
|
-
}
|
|
20
18
|
for (const encoding of encodings) {
|
|
21
19
|
for (const _id of [id + encoding, joinURL(id, "index.html" + encoding)]) {
|
|
22
20
|
const _asset = getAsset(_id);
|
|
@@ -34,6 +32,9 @@ export default defineHandler((event) => {
|
|
|
34
32
|
}
|
|
35
33
|
return;
|
|
36
34
|
}
|
|
35
|
+
if (encodings.length > 1) {
|
|
36
|
+
event.res.headers.append("Vary", "Accept-Encoding");
|
|
37
|
+
}
|
|
37
38
|
const ifNotMatch = event.req.headers.get("if-none-match") === asset.etag;
|
|
38
39
|
if (ifNotMatch) {
|
|
39
40
|
event.res.status = 304;
|
|
@@ -7,7 +7,9 @@ export declare function runTask<RT = unknown>(name: string, { payload, context }
|
|
|
7
7
|
context?: TaskContext;
|
|
8
8
|
}): Promise<TaskResult<RT>>;
|
|
9
9
|
/** @experimental */
|
|
10
|
-
export declare function startScheduleRunner(
|
|
10
|
+
export declare function startScheduleRunner({ waitUntil }?: {
|
|
11
|
+
waitUntil?: ((promise: Promise<unknown>) => void) | undefined;
|
|
12
|
+
}): void;
|
|
11
13
|
/** @experimental */
|
|
12
14
|
export declare function getCronTasks(cron: string): string[];
|
|
13
15
|
/** @experimental */
|
|
@@ -43,7 +43,7 @@ export async function runTask(name, { payload = {}, context = {} } = {}) {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
/** @experimental */
|
|
46
|
-
export function startScheduleRunner() {
|
|
46
|
+
export function startScheduleRunner({ waitUntil } = {}) {
|
|
47
47
|
if (!scheduledTasks || scheduledTasks.length === 0 || process.env.TEST) {
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
@@ -52,7 +52,7 @@ export function startScheduleRunner() {
|
|
|
52
52
|
new Cron(schedule.cron, async () => {
|
|
53
53
|
await Promise.all(schedule.tasks.map((name) => runTask(name, {
|
|
54
54
|
payload,
|
|
55
|
-
context: {}
|
|
55
|
+
context: { waitUntil }
|
|
56
56
|
}).catch((error) => {
|
|
57
57
|
console.error(`Error while running scheduled task "${name}"`, error);
|
|
58
58
|
})));
|
|
@@ -3,13 +3,16 @@ import wsAdapter from "crossws/adapters/node";
|
|
|
3
3
|
|
|
4
4
|
import { useNitroApp } from "nitro/app";
|
|
5
5
|
import { resolveWebsocketHooks } from "#nitro/runtime/app";
|
|
6
|
+
import { startScheduleRunner } from "#nitro/runtime/task";
|
|
6
7
|
|
|
7
8
|
const nitroApp = useNitroApp();
|
|
8
9
|
|
|
9
10
|
export const fetch = nitroApp.fetch;
|
|
10
11
|
|
|
11
|
-
const ws = import.meta._websocket
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const ws = import.meta._websocket ? wsAdapter({ resolve: resolveWebsocketHooks }) : undefined;
|
|
13
|
+
|
|
14
|
+
if (import.meta._tasks) {
|
|
15
|
+
startScheduleRunner({});
|
|
16
|
+
}
|
|
14
17
|
|
|
15
18
|
export const handleUpgrade = ws?.handleUpgrade;
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { ModuleRunner, ESModulesEvaluator } from "vite/module-runner";
|
|
2
|
+
import { createViteTransport } from "env-runner/vite";
|
|
3
|
+
|
|
4
|
+
// Custom evaluator for workerd where `new AsyncFunction()` is disallowed.
|
|
5
|
+
// Uses the unsafeEvalBinding exposed by the env-runner miniflare wrapper.
|
|
6
|
+
class WorkerdModuleEvaluator {
|
|
7
|
+
startOffset = 0;
|
|
8
|
+
|
|
9
|
+
async runInlinedModule(context, code) {
|
|
10
|
+
const unsafeEval = globalThis.__ENV_RUNNER_UNSAFE_EVAL__;
|
|
11
|
+
const keys = Object.keys(context);
|
|
12
|
+
const fn = unsafeEval.newAsyncFunction('"use strict";' + code, "runInlinedModule", ...keys);
|
|
13
|
+
await fn(...keys.map((k) => context[k]));
|
|
14
|
+
Object.seal(context[Object.keys(context)[0]]);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
runExternalModule(filepath) {
|
|
18
|
+
return import(filepath);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// ----- IPC -----
|
|
23
|
+
|
|
24
|
+
let sendMessage;
|
|
25
|
+
const messageListeners = new Set();
|
|
26
|
+
|
|
27
|
+
// ----- Environment runners -----
|
|
28
|
+
|
|
29
|
+
const envs = (globalThis.__nitro_vite_envs__ ??= {
|
|
30
|
+
nitro: undefined,
|
|
31
|
+
ssr: undefined,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
class ViteEnvRunner {
|
|
35
|
+
constructor({ name, entry }) {
|
|
36
|
+
this.name = name;
|
|
37
|
+
this.entryPath = entry;
|
|
38
|
+
|
|
39
|
+
this.entry = undefined;
|
|
40
|
+
this.entryError = undefined;
|
|
41
|
+
|
|
42
|
+
// Create Vite Module Runner
|
|
43
|
+
// https://vite.dev/guide/api-environment-runtimes.html#modulerunner
|
|
44
|
+
const onMessage = (listener) => messageListeners.add(listener);
|
|
45
|
+
const transport = createViteTransport((data) => sendMessage?.(data), onMessage, name);
|
|
46
|
+
const evaluator = globalThis.__ENV_RUNNER_UNSAFE_EVAL__
|
|
47
|
+
? new WorkerdModuleEvaluator()
|
|
48
|
+
: new ESModulesEvaluator();
|
|
49
|
+
const debug =
|
|
50
|
+
typeof process !== "undefined" && process.env?.NITRO_DEBUG ? console.debug : undefined;
|
|
51
|
+
this.runner = new ModuleRunner({ transport }, evaluator, debug);
|
|
52
|
+
|
|
53
|
+
this.reload();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async reload() {
|
|
57
|
+
try {
|
|
58
|
+
this.entry = await this.runner.import(this.entryPath);
|
|
59
|
+
this.entryError = undefined;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error(error);
|
|
62
|
+
this.entryError = error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async fetch(req, init) {
|
|
67
|
+
if (this.entryError) {
|
|
68
|
+
return renderError(req, this.entryError);
|
|
69
|
+
}
|
|
70
|
+
for (let i = 0; i < 5 && !(this.entry || this.entryError); i++) {
|
|
71
|
+
await new Promise((r) => setTimeout(r, 100 * Math.pow(2, i)));
|
|
72
|
+
}
|
|
73
|
+
if (this.entryError) {
|
|
74
|
+
return renderError(req, this.entryError);
|
|
75
|
+
}
|
|
76
|
+
if (!this.entry) {
|
|
77
|
+
throw httpError(503, `Vite environment "${this.name}" is unavailable`);
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const entryFetch = this.entry.fetch || this.entry.default?.fetch;
|
|
81
|
+
if (!entryFetch) {
|
|
82
|
+
throw httpError(500, `No fetch handler exported from ${this.entryPath}`);
|
|
83
|
+
}
|
|
84
|
+
return await entryFetch(req, init);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
return renderError(req, error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ----- RPC -----
|
|
92
|
+
|
|
93
|
+
const rpcRequests = new Map();
|
|
94
|
+
|
|
95
|
+
function rpc(name, data, timeout = 3000) {
|
|
96
|
+
const id = Math.random().toString(36).slice(2);
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
const timer = setTimeout(() => {
|
|
99
|
+
rpcRequests.delete(id);
|
|
100
|
+
reject(new Error(`RPC "${name}" timed out`));
|
|
101
|
+
}, timeout);
|
|
102
|
+
rpcRequests.set(id, { resolve, reject, timer });
|
|
103
|
+
sendMessage?.({ __rpc: name, __rpc_id: id, data });
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Trap unhandled errors to avoid worker crash
|
|
108
|
+
if (typeof process !== "undefined" && typeof process.on === "function") {
|
|
109
|
+
process.on("unhandledRejection", (error) => console.error(error));
|
|
110
|
+
process.on("uncaughtException", (error) => console.error(error));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ----- RSC Support -----
|
|
114
|
+
|
|
115
|
+
// define __VITE_ENVIRONMENT_RUNNER_IMPORT__ for RSC support
|
|
116
|
+
// https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-rsc/README.md#__vite_environment_runner_import__
|
|
117
|
+
|
|
118
|
+
globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__ = async function (environmentName, id) {
|
|
119
|
+
const env = envs[environmentName];
|
|
120
|
+
if (!env) {
|
|
121
|
+
throw new Error(`Vite environment "${environmentName}" is not registered`);
|
|
122
|
+
}
|
|
123
|
+
return env.runner.import(id);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// ----- Reload -----
|
|
127
|
+
|
|
128
|
+
async function reload() {
|
|
129
|
+
try {
|
|
130
|
+
await Promise.all(Object.values(envs).map((env) => env?.reload()));
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.error(error);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// eslint-disable-next-line unicorn/prefer-top-level-await
|
|
137
|
+
reload();
|
|
138
|
+
|
|
139
|
+
// ----- HTML Transform -----
|
|
140
|
+
|
|
141
|
+
globalThis.__transform_html__ = async function (html) {
|
|
142
|
+
html = await rpc("transformHTML", html).catch((error) => {
|
|
143
|
+
console.warn("Failed to transform HTML via Vite:", error);
|
|
144
|
+
return html;
|
|
145
|
+
});
|
|
146
|
+
return html;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// ----- Exports (env-runner AppEntry) -----
|
|
150
|
+
|
|
151
|
+
export function fetch(req) {
|
|
152
|
+
const viteEnv = req?.headers.get("x-vite-env") || "nitro";
|
|
153
|
+
const env = envs[viteEnv];
|
|
154
|
+
if (!env) {
|
|
155
|
+
return renderError(req, httpError(500, `Unknown vite environment "${viteEnv}"`));
|
|
156
|
+
}
|
|
157
|
+
return env.fetch(req);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function upgrade(context) {
|
|
161
|
+
const handleUpgrade = envs.nitro?.entry?.handleUpgrade;
|
|
162
|
+
if (handleUpgrade) {
|
|
163
|
+
handleUpgrade(context.node.req, context.node.socket, context.node.head);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export const ipc = {
|
|
168
|
+
onOpen(ctx) {
|
|
169
|
+
sendMessage = ctx.sendMessage;
|
|
170
|
+
},
|
|
171
|
+
onMessage(message) {
|
|
172
|
+
if (message?.__rpc_id) {
|
|
173
|
+
const req = rpcRequests.get(message.__rpc_id);
|
|
174
|
+
if (req) {
|
|
175
|
+
clearTimeout(req.timer);
|
|
176
|
+
rpcRequests.delete(message.__rpc_id);
|
|
177
|
+
if (message.error) {
|
|
178
|
+
req.reject(typeof message.error === "string" ? new Error(message.error) : message.error);
|
|
179
|
+
} else {
|
|
180
|
+
req.resolve(message.data);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (message?.type === "custom") {
|
|
186
|
+
if (message.event === "nitro:vite-env") {
|
|
187
|
+
const { name, entry } = message.data;
|
|
188
|
+
if (!envs[name]) {
|
|
189
|
+
envs[name] = new ViteEnvRunner({ name, entry });
|
|
190
|
+
}
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (message?.type === "full-reload") {
|
|
195
|
+
reload();
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
for (const listener of messageListeners) {
|
|
199
|
+
listener(message);
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
onClose() {},
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// ----- Error handling -----
|
|
206
|
+
|
|
207
|
+
function httpError(status, message) {
|
|
208
|
+
const error = new Error(message || `HTTP Error ${status}`);
|
|
209
|
+
error.status = status;
|
|
210
|
+
error.name = "NitroViteError";
|
|
211
|
+
return error;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async function renderError(req, error) {
|
|
215
|
+
if (req.headers.get("accept")?.includes("application/json")) {
|
|
216
|
+
return new Response(
|
|
217
|
+
JSON.stringify(
|
|
218
|
+
{
|
|
219
|
+
status: error.status || 500,
|
|
220
|
+
name: error.name || "Error",
|
|
221
|
+
message: error.message,
|
|
222
|
+
stack: (error.stack || "")
|
|
223
|
+
.split("\n")
|
|
224
|
+
.splice(1)
|
|
225
|
+
.map((l) => l.trim()),
|
|
226
|
+
},
|
|
227
|
+
null,
|
|
228
|
+
2
|
|
229
|
+
),
|
|
230
|
+
{
|
|
231
|
+
status: error.status || 500,
|
|
232
|
+
headers: {
|
|
233
|
+
"Content-Type": "application/json",
|
|
234
|
+
"Cache-Control": "no-store, max-age=0, must-revalidate",
|
|
235
|
+
Pragma: "no-cache",
|
|
236
|
+
Expires: "0",
|
|
237
|
+
},
|
|
238
|
+
}
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
const { Youch } = await import("youch");
|
|
243
|
+
const youch = new Youch();
|
|
244
|
+
return new Response(await youch.toHTML(error), {
|
|
245
|
+
status: error.status || 500,
|
|
246
|
+
headers: {
|
|
247
|
+
"Content-Type": "text/html",
|
|
248
|
+
"Cache-Control": "no-store, max-age=0, must-revalidate",
|
|
249
|
+
Pragma: "no-cache",
|
|
250
|
+
Expires: "0",
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
} catch {
|
|
254
|
+
return new Response(`<pre>${error.stack || error.message || error}</pre>`, {
|
|
255
|
+
status: error.status || 500,
|
|
256
|
+
headers: {
|
|
257
|
+
"Content-Type": "text/html",
|
|
258
|
+
"Cache-Control": "no-store, max-age=0, must-revalidate",
|
|
259
|
+
Pragma: "no-cache",
|
|
260
|
+
Expires: "0",
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
package/dist/runtime/meta.mjs
CHANGED
package/dist/runtime/nitro.d.mts
CHANGED
|
@@ -5,5 +5,7 @@ export declare function defineConfig(config: Omit<NitroConfig, "rootDir">): Omit
|
|
|
5
5
|
export { defineNitroPlugin as definePlugin } from "./internal/plugin.mjs";
|
|
6
6
|
export { defineRouteMeta } from "./internal/meta.mjs";
|
|
7
7
|
export { defineNitroErrorHandler as defineErrorHandler } from "./internal/error/utils.mjs";
|
|
8
|
+
export { defineHandler, defineMiddleware, defineWebSocketHandler, html, HTTPError, HTTPResponse } from "h3";
|
|
9
|
+
export type { H3Event } from "h3";
|
|
8
10
|
export declare function serverFetch(resource: string | URL | Request, init?: RequestInit, context?: ServerRequestContext | H3EventContext): Promise<Response>;
|
|
9
11
|
export declare function fetch(resource: string | URL | Request, init?: RequestInit, context?: ServerRequestContext | H3EventContext): Promise<Response>;
|
package/dist/runtime/nitro.mjs
CHANGED
|
@@ -6,6 +6,8 @@ export function defineConfig(config) {
|
|
|
6
6
|
export { defineNitroPlugin as definePlugin } from "./internal/plugin.mjs";
|
|
7
7
|
export { defineRouteMeta } from "./internal/meta.mjs";
|
|
8
8
|
export { defineNitroErrorHandler as defineErrorHandler } from "./internal/error/utils.mjs";
|
|
9
|
+
// H3
|
|
10
|
+
export { defineHandler, defineMiddleware, defineWebSocketHandler, html, HTTPError, HTTPResponse } from "h3";
|
|
9
11
|
// Runtime
|
|
10
12
|
export function serverFetch(resource, init, context) {
|
|
11
13
|
const nitro = globalThis.__nitro__?.default || globalThis.__nitro__?.prerender || globalThis.__nitro_builder__;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import "./_runtime_warn.mjs";
|
|
2
|
+
import { type Storage } from "unstorage";
|
|
2
3
|
import type { AssetMeta } from "nitro/types";
|
|
3
|
-
export declare const assets:
|
|
4
|
+
export declare const assets: Storage;
|
|
4
5
|
export declare function readAsset<T = any>(_id: string): Promise<T>;
|
|
5
6
|
export declare function statAsset(_id: string): Promise<AssetMeta>;
|
|
6
7
|
export declare function getKeys(): Promise<string[]>;
|
package/dist/runtime/vite.d.mts
CHANGED
|
@@ -4,5 +4,5 @@ type FetchableEnv = {
|
|
|
4
4
|
declare global {
|
|
5
5
|
var __nitro_vite_envs__: Record<string, FetchableEnv>;
|
|
6
6
|
}
|
|
7
|
-
export declare function fetchViteEnv(viteEnvName: string, input: RequestInfo | URL, init?: RequestInit)
|
|
7
|
+
export declare function fetchViteEnv(viteEnvName: string, input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
8
8
|
export {};
|