nitro 3.0.260415-beta → 3.0.260522-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/dist/THIRD-PARTY-LICENSES.md.gz +0 -0
- package/dist/_build/common.mjs +157 -45
- package/dist/_build/rolldown.mjs +6 -6
- package/dist/_build/rollup.mjs +11 -11
- package/dist/_build/vite.build.mjs +3 -3
- package/dist/_build/vite.dev.mjs +149 -0
- package/dist/_build/vite.env.mjs +177 -0
- package/dist/_chunks/nitro.mjs +241 -14
- package/dist/_chunks/nitro2.mjs +117 -90
- package/dist/_chunks/utils.mjs +4 -4
- package/dist/_common.mjs +2 -2
- package/dist/_dev.d.mts +1 -1
- package/dist/_dev.mjs +7 -6
- package/dist/_libs/c12+rc9.mjs +24 -11
- package/dist/_libs/c12+readdirp+chokidar.d.mts +7 -8
- package/dist/_libs/citty.mjs +1 -1
- package/dist/_libs/common.d.mts +37 -0
- package/dist/_libs/commondir+is-reference.mjs +3 -3
- package/dist/_libs/compatx.d.mts +1 -1
- package/dist/_libs/compatx.mjs +1 -1
- package/dist/_libs/estree+pluginutils.d.mts +1 -1
- package/dist/_libs/estree-walker.mjs +1 -1
- package/dist/_libs/hasown+resolve+deepmerge.mjs +62 -49
- package/dist/_libs/httpxy.d.mts +2 -4
- package/dist/_libs/httpxy.mjs +13 -9
- package/dist/_libs/jsonc-parser+workers-utils.d.mts +1579 -0
- package/dist/_libs/klona.mjs +1 -1
- package/dist/_libs/magic-string.d.mts +1 -1
- package/dist/_libs/mlly.d.mts +1 -1
- package/dist/_libs/nypm+tinyexec.mjs +137 -113
- package/dist/_libs/openapi-types.d.mts +730 -0
- package/dist/_libs/perfect-debounce.mjs +1 -1
- package/dist/_libs/pkg-types.d.mts +8 -5
- package/dist/_libs/plugin-alias.mjs +2 -2
- package/dist/_libs/plugin-inject.mjs +4 -2
- package/dist/_libs/plugin-json.mjs +2 -2
- package/dist/_libs/pluginutils.mjs +18 -5
- package/dist/_libs/readdirp+chokidar.mjs +4 -3
- package/dist/_libs/remapping.mjs +2 -2
- package/dist/_libs/resolve-uri+gen-mapping.mjs +2 -5
- package/dist/_libs/rou3.d.mts +1 -1
- package/dist/_libs/rou3.mjs +1 -1
- package/dist/_libs/std-env.d.mts +1 -1
- package/dist/_libs/tsconfck.mjs +1 -1
- package/dist/_libs/ultrahtml.mjs +1 -1
- package/dist/_libs/unimport+unplugin.mjs +61 -39
- package/dist/_libs/unplugin+unimport.d.mts +4 -4
- package/dist/_libs/unwasm.d.mts +1 -1
- package/dist/_presets.mjs +118 -91
- package/dist/builder.d.mts +1 -1
- package/dist/builder.mjs +3 -3
- package/dist/cli/_chunks/build.mjs +3 -3
- package/dist/cli/_chunks/common.mjs +1 -1
- package/dist/cli/_chunks/deploy.mjs +2 -2
- package/dist/cli/_chunks/dev.mjs +4 -4
- package/dist/cli/_chunks/docs.mjs +1 -1
- package/dist/cli/_chunks/list.mjs +2 -2
- package/dist/cli/_chunks/prepare.mjs +3 -3
- package/dist/cli/_chunks/preview.mjs +4 -4
- package/dist/cli/_chunks/run.mjs +2 -2
- package/dist/cli/_chunks/task.mjs +1 -1
- package/dist/cli/index.mjs +1 -1
- package/dist/docs/0.docs/5.cache.md +53 -9
- package/dist/docs/1.deploy/2.providers/2.aws-amplify.md +3 -3
- package/dist/docs/1.deploy/2.providers/21.vercel.md +6 -0
- package/dist/docs/3.examples/27.vite-ssr-tsr-react.md +1 -1
- package/dist/node_modules/ufo/dist/index.mjs +2 -2
- package/dist/node_modules/ufo/package.json +9 -9
- package/dist/presets/azure/runtime/azure-swa.mjs +2 -0
- package/dist/presets/vercel/runtime/queue.dev.mjs +41 -0
- package/dist/runtime/internal/app.mjs +4 -111
- package/dist/runtime/internal/route-rules.d.mts +1 -0
- package/dist/runtime/internal/route-rules.mjs +29 -1
- package/dist/runtime/internal/routes/scalar.mjs +1 -0
- package/dist/runtime/virtual/app.d.mts +4 -0
- package/dist/runtime/virtual/app.mjs +32 -0
- package/dist/types/index.d.mts +959 -1836
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +23 -331
- package/package.json +43 -44
- package/dist/THIRD-PARTY-LICENSES.md +0 -1646
- package/dist/_chunks/nitro3.mjs +0 -136
- package/dist/_chunks/nitro4.mjs +0 -127
- package/dist/_libs/_.mjs +0 -2
- package/dist/_libs/_2.mjs +0 -2
- package/dist/_libs/_3.mjs +0 -2
- package/dist/_libs/_4.mjs +0 -2
- package/dist/_libs/_5.mjs +0 -2
- package/dist/_libs/_6.mjs +0 -2
- package/dist/_libs/_7.mjs +0 -2
- package/dist/_libs/escape-string-regexp.mjs +0 -5
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { toRequest } from "h3";
|
|
2
2
|
import { HookableCore } from "hookable";
|
|
3
|
-
import { nitroAsyncContext } from "./context.mjs";
|
|
4
3
|
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import { findRoute, findRouteRules, globalMiddleware, findRoutedMiddleware } from "#nitro/virtual/routing";
|
|
8
|
-
import { hasRouteRules, hasRoutedMiddleware, hasGlobalMiddleware, hasRoutes, hasHooks, hasPlugins } from "#nitro/virtual/feature-flags";
|
|
4
|
+
import { findRouteRules } from "#nitro/virtual/routing";
|
|
5
|
+
import { createNitroApp, initNitroPlugins } from "#nitro/virtual/app";
|
|
9
6
|
const APP_ID = import.meta.prerender ? "prerender" : "default";
|
|
10
7
|
export function useNitroApp() {
|
|
11
8
|
let instance = useNitroApp._instance;
|
|
@@ -15,9 +12,7 @@ export function useNitroApp() {
|
|
|
15
12
|
instance = useNitroApp._instance = createNitroApp();
|
|
16
13
|
globalThis.__nitro__ = globalThis.__nitro__ || {};
|
|
17
14
|
globalThis.__nitro__[APP_ID] = instance;
|
|
18
|
-
|
|
19
|
-
initNitroPlugins(instance);
|
|
20
|
-
}
|
|
15
|
+
initNitroPlugins(instance);
|
|
21
16
|
return instance;
|
|
22
17
|
}
|
|
23
18
|
export function useNitroHooks() {
|
|
@@ -53,108 +48,6 @@ export function fetch(resource, init, context) {
|
|
|
53
48
|
resource = resource._request || resource;
|
|
54
49
|
return globalThis.fetch(resource, init);
|
|
55
50
|
}
|
|
56
|
-
function createNitroApp() {
|
|
57
|
-
const hooks = hasHooks ? new HookableCore() : undefined;
|
|
58
|
-
const captureError = (error, errorCtx) => {
|
|
59
|
-
const promise = hasHooks && hooks.callHook("error", error, errorCtx)?.catch?.((hookError) => {
|
|
60
|
-
console.error("Error while capturing another error", hookError);
|
|
61
|
-
});
|
|
62
|
-
if (errorCtx?.event) {
|
|
63
|
-
const errors = errorCtx.event.req.context?.nitro?.errors;
|
|
64
|
-
if (errors) {
|
|
65
|
-
errors.push({
|
|
66
|
-
error,
|
|
67
|
-
context: errorCtx
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
if (hasHooks && promise && typeof errorCtx.event.req.waitUntil === "function") {
|
|
71
|
-
errorCtx.event.req.waitUntil(promise);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const h3App = createH3App({ onError(error, event) {
|
|
76
|
-
hasHooks && captureError(error, { event });
|
|
77
|
-
return errorHandler(error, event);
|
|
78
|
-
} });
|
|
79
|
-
if (hasHooks) {
|
|
80
|
-
h3App.config.onRequest = (event) => {
|
|
81
|
-
return hooks.callHook("request", event)?.catch?.((error) => {
|
|
82
|
-
captureError(error, {
|
|
83
|
-
event,
|
|
84
|
-
tags: ["request"]
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
h3App.config.onResponse = (res, event) => {
|
|
89
|
-
return hooks.callHook("response", res, event)?.catch?.((error) => {
|
|
90
|
-
captureError(error, {
|
|
91
|
-
event,
|
|
92
|
-
tags: ["response"]
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
let appHandler = (req) => {
|
|
98
|
-
req.context ||= {};
|
|
99
|
-
req.context.nitro = req.context.nitro || { errors: [] };
|
|
100
|
-
return h3App.fetch(req);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
if (import.meta._asyncContext) {
|
|
104
|
-
const originalHandler = appHandler;
|
|
105
|
-
appHandler = (req) => {
|
|
106
|
-
const asyncCtx = { request: req };
|
|
107
|
-
return nitroAsyncContext.callAsync(asyncCtx, () => originalHandler(req));
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
const app = {
|
|
111
|
-
fetch: appHandler,
|
|
112
|
-
h3: h3App,
|
|
113
|
-
hooks,
|
|
114
|
-
captureError
|
|
115
|
-
};
|
|
116
|
-
return app;
|
|
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
|
-
}
|
|
129
|
-
function createH3App(config) {
|
|
130
|
-
|
|
131
|
-
const h3App = new H3Core(config);
|
|
132
|
-
|
|
133
|
-
hasRoutes && (h3App["~findRoute"] = (event) => findRoute(event.req.method, event.url.pathname));
|
|
134
|
-
hasGlobalMiddleware && h3App["~middleware"].push(...globalMiddleware);
|
|
135
|
-
if (hasRouteRules || hasRoutedMiddleware) {
|
|
136
|
-
h3App["~getMiddleware"] = (event, route) => {
|
|
137
|
-
const needsRouting = hasRouteRules || hasRoutedMiddleware;
|
|
138
|
-
const pathname = needsRouting ? event.url.pathname : undefined;
|
|
139
|
-
const method = needsRouting ? event.req.method : undefined;
|
|
140
|
-
const middleware = [];
|
|
141
|
-
if (hasRouteRules) {
|
|
142
|
-
const routeRules = getRouteRules(method, pathname);
|
|
143
|
-
event.context.routeRules = routeRules?.routeRules;
|
|
144
|
-
if (routeRules?.routeRuleMiddleware.length) {
|
|
145
|
-
middleware.push(...routeRules.routeRuleMiddleware);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
hasGlobalMiddleware && middleware.push(...h3App["~middleware"]);
|
|
149
|
-
hasRoutedMiddleware && middleware.push(...findRoutedMiddleware(method, pathname).map((r) => r.data));
|
|
150
|
-
if (hasRoutes && route?.data?.middleware?.length) {
|
|
151
|
-
middleware.push(...route.data.middleware);
|
|
152
|
-
}
|
|
153
|
-
return middleware;
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
return h3App;
|
|
157
|
-
}
|
|
158
51
|
export function getRouteRules(method, pathname) {
|
|
159
52
|
const m = findRouteRules(method, pathname);
|
|
160
53
|
if (!m?.length) {
|
|
@@ -8,4 +8,5 @@ export declare const redirect: RouteRuleCtor<"redirect">;
|
|
|
8
8
|
export declare const proxy: RouteRuleCtor<"proxy">;
|
|
9
9
|
export declare const cache: RouteRuleCtor<"cache">;
|
|
10
10
|
export declare const basicAuth: RouteRuleCtor<"auth">;
|
|
11
|
+
export declare function isPathInScope(pathname: string, base: string): boolean;
|
|
11
12
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { proxyRequest, redirect as sendRedirect, requireBasicAuth } from "h3";
|
|
1
|
+
import { HTTPError, proxyRequest, redirect as sendRedirect, requireBasicAuth } from "h3";
|
|
2
2
|
import { joinURL, withQuery, withoutBase } from "ufo";
|
|
3
3
|
import { defineCachedHandler } from "./cache.mjs";
|
|
4
4
|
|
|
@@ -17,7 +17,12 @@ export const redirect = ((m) => function redirectRouteRule(event) {
|
|
|
17
17
|
let targetPath = event.url.pathname + event.url.search;
|
|
18
18
|
const strpBase = m.options._redirectStripBase;
|
|
19
19
|
if (strpBase) {
|
|
20
|
+
if (!isPathInScope(event.url.pathname, strpBase)) {
|
|
21
|
+
throw new HTTPError({ status: 400 });
|
|
22
|
+
}
|
|
20
23
|
targetPath = withoutBase(targetPath, strpBase);
|
|
24
|
+
} else if (targetPath.startsWith("//")) {
|
|
25
|
+
targetPath = targetPath.replace(/^\/+/, "/");
|
|
21
26
|
}
|
|
22
27
|
target = joinURL(target.slice(0, -3), targetPath);
|
|
23
28
|
} else if (event.url.search) {
|
|
@@ -35,7 +40,12 @@ export const proxy = ((m) => function proxyRouteRule(event) {
|
|
|
35
40
|
let targetPath = event.url.pathname + event.url.search;
|
|
36
41
|
const strpBase = m.options._proxyStripBase;
|
|
37
42
|
if (strpBase) {
|
|
43
|
+
if (!isPathInScope(event.url.pathname, strpBase)) {
|
|
44
|
+
throw new HTTPError({ status: 400 });
|
|
45
|
+
}
|
|
38
46
|
targetPath = withoutBase(targetPath, strpBase);
|
|
47
|
+
} else if (targetPath.startsWith("//")) {
|
|
48
|
+
targetPath = targetPath.replace(/^\/+/, "/");
|
|
39
49
|
}
|
|
40
50
|
target = joinURL(target.slice(0, -3), targetPath);
|
|
41
51
|
} else if (event.url.search) {
|
|
@@ -72,3 +82,21 @@ export const basicAuth = /* @__PURE__ */ Object.assign(((m) => async function au
|
|
|
72
82
|
await requireBasicAuth(event, m.options);
|
|
73
83
|
return next();
|
|
74
84
|
}), { order: -1 });
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
export function isPathInScope(pathname, base) {
|
|
94
|
+
let canonical;
|
|
95
|
+
try {
|
|
96
|
+
const pre = pathname.replace(/%2f/gi, "/").replace(/%5c/gi, "\\");
|
|
97
|
+
canonical = new URL(pre, "http://_").pathname;
|
|
98
|
+
} catch {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
return !base || canonical === base || canonical.startsWith(base + "/");
|
|
102
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import "./_runtime_warn.mjs";
|
|
2
|
+
import { H3Core } from "h3";
|
|
3
|
+
import errorHandler from "#nitro/virtual/error-handler";
|
|
4
|
+
export function createNitroApp() {
|
|
5
|
+
const h3App = new H3Core({ onError(error, event) {
|
|
6
|
+
return errorHandler(error, event);
|
|
7
|
+
} });
|
|
8
|
+
const captureError = (error, errorCtx) => {
|
|
9
|
+
if (errorCtx?.event) {
|
|
10
|
+
const errors = errorCtx.event.req.context?.nitro?.errors;
|
|
11
|
+
if (errors) {
|
|
12
|
+
errors.push({
|
|
13
|
+
error,
|
|
14
|
+
context: errorCtx
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
fetch: (req) => {
|
|
21
|
+
req.context ||= {};
|
|
22
|
+
req.context.nitro = req.context.nitro || { errors: [] };
|
|
23
|
+
return h3App.fetch(req);
|
|
24
|
+
},
|
|
25
|
+
h3: h3App,
|
|
26
|
+
hooks: undefined,
|
|
27
|
+
captureError
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function initNitroPlugins(app) {
|
|
31
|
+
return app;
|
|
32
|
+
}
|