nitro-nightly 3.1.0-20251026-222805-a13234bf → 3.1.0-20251027-223403-81bd673d
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/_chunks/index.mjs +3 -0
- package/dist/_chunks/info.mjs +10 -6
- package/dist/presets/standard/runtime/server.d.mts +1 -1
- package/dist/presets/standard/runtime/server.mjs +1 -1
- package/dist/runtime/internal/app.mjs +31 -15
- package/dist/runtime/internal/error/prod.d.mts +3 -2
- package/dist/runtime/internal/error/prod.mjs +9 -13
- package/dist/runtime/internal/routes/dev-tasks.d.mts +30 -2
- package/dist/types/index.d.mts +1 -0
- package/package.json +2 -2
package/dist/_chunks/index.mjs
CHANGED
|
@@ -20679,6 +20679,9 @@ class Router {
|
|
|
20679
20679
|
addRoute(this.#router, route.method, route.route, route.data);
|
|
20680
20680
|
}
|
|
20681
20681
|
}
|
|
20682
|
+
hasRoutes() {
|
|
20683
|
+
return this.#routes.length > 0;
|
|
20684
|
+
}
|
|
20682
20685
|
compileToString(opts) {
|
|
20683
20686
|
return this.#compiled || (this.#compiled = compileRouterToString(this.#router, void 0, opts));
|
|
20684
20687
|
}
|
package/dist/_chunks/info.mjs
CHANGED
|
@@ -10350,7 +10350,8 @@ function routing(nitro) {
|
|
|
10350
10350
|
"_importHash"
|
|
10351
10351
|
);
|
|
10352
10352
|
const h3Imports = [
|
|
10353
|
-
|
|
10353
|
+
allHandlers.some((h) => !h.lazy) && "toEventHandler",
|
|
10354
|
+
nitro.options.serverEntry && "toMiddleware",
|
|
10354
10355
|
allHandlers.some((h) => h.lazy) && "defineLazyEventHandler"
|
|
10355
10356
|
].filter(Boolean);
|
|
10356
10357
|
return (
|
|
@@ -10360,6 +10361,7 @@ import * as __routeRules__ from "nitro/runtime/internal/route-rules";
|
|
|
10360
10361
|
${nitro.options.serverEntry ? `import __serverEntry__ from ${JSON.stringify(nitro.options.serverEntry)};` : ""}
|
|
10361
10362
|
import {${h3Imports.join(", ")}} from "nitro/deps/h3";
|
|
10362
10363
|
|
|
10364
|
+
export const hasRouteRules = ${nitro.routing.routeRules.hasRoutes() ? "true" : "false"};
|
|
10363
10365
|
export const findRouteRules = ${nitro.routing.routeRules.compileToString({ serialize: serializeRouteRule, matchAll: true })}
|
|
10364
10366
|
|
|
10365
10367
|
${allHandlers.filter((h) => !h.lazy).map((h) => (
|
|
@@ -10374,15 +10376,17 @@ ${allHandlers.filter((h) => h.lazy).map(
|
|
|
10374
10376
|
)
|
|
10375
10377
|
).join("\n")}
|
|
10376
10378
|
|
|
10379
|
+
export const hasRoutes = ${nitro.routing.routes.hasRoutes() ? "true" : "false"};
|
|
10377
10380
|
export const findRoute = ${nitro.routing.routes.compileToString({ serialize: serializeHandler })}
|
|
10378
10381
|
|
|
10382
|
+
export const hasRoutedMiddleware = ${nitro.routing.routedMiddleware.hasRoutes() ? "true" : "false"};
|
|
10379
10383
|
export const findRoutedMiddleware = ${nitro.routing.routedMiddleware.compileToString({ serialize: serializeHandler, matchAll: true })};
|
|
10380
10384
|
|
|
10381
|
-
export const
|
|
10382
|
-
|
|
10383
|
-
${nitro.
|
|
10384
|
-
|
|
10385
|
-
|
|
10385
|
+
export const hasGlobalMiddleware = ${nitro.routing.globalMiddleware.length > 0 || nitro.options.serverEntry ? "true" : "false"};
|
|
10386
|
+
export const globalMiddleware = [
|
|
10387
|
+
${nitro.routing.globalMiddleware.map((h) => h.lazy ? h._importHash : `toEventHandler(${h._importHash})`).join(",")}
|
|
10388
|
+
${nitro.options.serverEntry ? `,toMiddleware(__serverEntry__)` : ""}
|
|
10389
|
+
].filter(Boolean);
|
|
10386
10390
|
`
|
|
10387
10391
|
);
|
|
10388
10392
|
},
|
|
@@ -4,10 +4,14 @@ import { nitroAsyncContext } from "./context.mjs";
|
|
|
4
4
|
import errorHandler from "#nitro-internal-virtual/error-handler";
|
|
5
5
|
import { plugins } from "#nitro-internal-virtual/plugins";
|
|
6
6
|
import {
|
|
7
|
+
hasRouteRules,
|
|
7
8
|
findRoute,
|
|
8
9
|
findRouteRules,
|
|
9
10
|
globalMiddleware,
|
|
10
|
-
findRoutedMiddleware
|
|
11
|
+
findRoutedMiddleware,
|
|
12
|
+
hasRoutedMiddleware,
|
|
13
|
+
hasGlobalMiddleware,
|
|
14
|
+
hasRoutes
|
|
11
15
|
} from "#nitro-internal-virtual/routing";
|
|
12
16
|
export function useNitroApp() {
|
|
13
17
|
return useNitroApp.__instance__ ??= initNitroApp();
|
|
@@ -59,7 +63,7 @@ function createNitroApp() {
|
|
|
59
63
|
let fetchHandler = (req) => {
|
|
60
64
|
req.context ??= {};
|
|
61
65
|
req.context.nitro = req.context.nitro || { errors: [] };
|
|
62
|
-
return h3App.
|
|
66
|
+
return h3App.fetch(req);
|
|
63
67
|
};
|
|
64
68
|
if (import.meta._asyncContext) {
|
|
65
69
|
const originalFetchHandler = fetchHandler;
|
|
@@ -97,19 +101,31 @@ function createNitroApp() {
|
|
|
97
101
|
}
|
|
98
102
|
function createH3App(config) {
|
|
99
103
|
const h3App = new H3Core(config);
|
|
100
|
-
h3App
|
|
101
|
-
h3App.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
hasRoutes && (h3App["~findRoute"] = (event) => findRoute(event.req.method, event.url.pathname));
|
|
105
|
+
hasGlobalMiddleware && h3App["~middleware"].push(...globalMiddleware);
|
|
106
|
+
if (hasRouteRules || hasRoutedMiddleware) {
|
|
107
|
+
h3App["~getMiddleware"] = (event, route) => {
|
|
108
|
+
const needsRouting = hasRouteRules || hasRoutedMiddleware;
|
|
109
|
+
const pathname = needsRouting ? event.url.pathname : void 0;
|
|
110
|
+
const method = needsRouting ? event.req.method : void 0;
|
|
111
|
+
const middleware = [];
|
|
112
|
+
if (hasRouteRules) {
|
|
113
|
+
const routeRules = getRouteRules(method, pathname);
|
|
114
|
+
event.context.routeRules = routeRules?.routeRules;
|
|
115
|
+
if (routeRules?.routeRuleMiddleware.length) {
|
|
116
|
+
middleware.push(...routeRules.routeRuleMiddleware);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
hasGlobalMiddleware && middleware.push(...h3App["~middleware"]);
|
|
120
|
+
hasRoutedMiddleware && middleware.push(
|
|
121
|
+
...findRoutedMiddleware(method, pathname).map((r) => r.data)
|
|
122
|
+
);
|
|
123
|
+
if (hasRoutes && route?.data?.middleware?.length) {
|
|
124
|
+
middleware.push(...route.data.middleware);
|
|
125
|
+
}
|
|
126
|
+
return middleware;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
113
129
|
return h3App;
|
|
114
130
|
}
|
|
115
131
|
function getRouteRules(method, pathname) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { HTTPError, HTTPEvent } from "h3";
|
|
2
2
|
import type { InternalHandlerResponse } from "./utils.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import type { NitroErrorHandler } from "nitro/types";
|
|
4
|
+
declare const errorHandler: NitroErrorHandler;
|
|
5
|
+
export default errorHandler;
|
|
5
6
|
export declare function defaultHandler(error: HTTPError, event: HTTPEvent, opts?: {
|
|
6
7
|
silent?: boolean;
|
|
7
8
|
json?: boolean;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { getRequestURL } from "h3";
|
|
2
|
-
import { defineNitroErrorHandler } from "./utils.mjs";
|
|
3
1
|
import { FastResponse } from "srvx";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
);
|
|
2
|
+
const errorHandler = (error, event) => {
|
|
3
|
+
const res = defaultHandler(error, event);
|
|
4
|
+
return new FastResponse(
|
|
5
|
+
typeof res.body === "string" ? res.body : JSON.stringify(res.body, null, 2),
|
|
6
|
+
res
|
|
7
|
+
);
|
|
8
|
+
};
|
|
9
|
+
export default errorHandler;
|
|
10
10
|
export function defaultHandler(error, event, opts) {
|
|
11
11
|
const isSensitive = error.unhandled;
|
|
12
12
|
const status = error.status || 500;
|
|
13
|
-
const url =
|
|
13
|
+
const url = event.url || new URL(event.req.url);
|
|
14
14
|
if (status === 404) {
|
|
15
15
|
const baseURL = import.meta.baseURL || "/";
|
|
16
16
|
if (/^\/[^/]/.test(baseURL) && !url.pathname.startsWith(baseURL)) {
|
|
@@ -33,13 +33,9 @@ export function defaultHandler(error, event, opts) {
|
|
|
33
33
|
}
|
|
34
34
|
const headers = {
|
|
35
35
|
"content-type": "application/json",
|
|
36
|
-
// Prevent browser from guessing the MIME types of resources.
|
|
37
36
|
"x-content-type-options": "nosniff",
|
|
38
|
-
// Prevent error page from being embedded in an iframe
|
|
39
37
|
"x-frame-options": "DENY",
|
|
40
|
-
// Prevent browsers from sending the Referer header
|
|
41
38
|
"referrer-policy": "no-referrer",
|
|
42
|
-
// Disable the execution of any js
|
|
43
39
|
"content-security-policy": "script-src 'none'; frame-ancestors 'none';"
|
|
44
40
|
};
|
|
45
41
|
if (status === 404 || !event.res.headers.has("cache-control")) {
|
|
@@ -1,3 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
declare const _default: {
|
|
2
|
+
"~rou3": import("h3").RouterContext;
|
|
3
|
+
request(request: import("srvx").ServerRequest | URL | string, options?: RequestInit, context?: import("h3").H3EventContext): Response | Promise<Response>;
|
|
4
|
+
use(route: string, handler: import("h3").Middleware, opts?: import("h3").MiddlewareOptions): /*elided*/ any;
|
|
5
|
+
use(handler: import("h3").Middleware, opts?: import("h3").MiddlewareOptions): /*elided*/ any;
|
|
6
|
+
on(method: import("h3").HTTPMethod | Lowercase<import("h3").HTTPMethod> | "", route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
7
|
+
register(plugin: import("h3").H3Plugin): /*elided*/ any;
|
|
8
|
+
mount(base: string, input: import("srvx").FetchHandler | {
|
|
9
|
+
fetch: import("srvx").FetchHandler;
|
|
10
|
+
} | /*elided*/ any): /*elided*/ any;
|
|
11
|
+
all(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
12
|
+
get(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
13
|
+
post(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
14
|
+
put(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
15
|
+
delete(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
16
|
+
patch(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
17
|
+
head(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
18
|
+
options(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
19
|
+
connect(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
20
|
+
trace(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
21
|
+
readonly config: import("h3").H3Config;
|
|
22
|
+
"~middleware": import("h3").Middleware[];
|
|
23
|
+
"~routes": import("h3").H3Route[];
|
|
24
|
+
fetch(_request: import("srvx").ServerRequest): Response | Promise<Response>;
|
|
25
|
+
handler(event: import("h3").H3Event): unknown | Promise<unknown>;
|
|
26
|
+
"~request"(request: import("srvx").ServerRequest, context?: import("h3").H3EventContext): Response | Promise<Response>;
|
|
27
|
+
"~findRoute"(_event: import("h3").H3Event): import("h3").MatchedRoute<import("h3").H3Route> | void;
|
|
28
|
+
"~getMiddleware"(event: import("h3").H3Event, route: import("h3").MatchedRoute<import("h3").H3Route> | undefined): import("h3").Middleware[];
|
|
29
|
+
"~addRoute"(_route: import("h3").H3Route): void;
|
|
30
|
+
};
|
|
3
31
|
export default _default;
|
package/dist/types/index.d.mts
CHANGED
|
@@ -3817,6 +3817,7 @@ declare class Router<T> {
|
|
|
3817
3817
|
constructor(matchAll?: boolean);
|
|
3818
3818
|
get routes(): Route<T>[];
|
|
3819
3819
|
_update(routes: Route<T>[]): void;
|
|
3820
|
+
hasRoutes(): boolean;
|
|
3820
3821
|
compileToString(opts?: RouterCompilerOptions): string;
|
|
3821
3822
|
match(method: string, path: string): undefined | T;
|
|
3822
3823
|
matchAll(method: string, path: string): T[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-nightly",
|
|
3
|
-
"version": "3.1.0-
|
|
3
|
+
"version": "3.1.0-20251027-223403-81bd673d",
|
|
4
4
|
"description": "Build and Deploy Universal JavaScript Servers",
|
|
5
5
|
"homepage": "https://nitro.build",
|
|
6
6
|
"repository": "nitrojs/nitro",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"db0": "^0.3.4",
|
|
59
59
|
"esbuild": "^0.25.11",
|
|
60
60
|
"fetchdts": "^0.1.7",
|
|
61
|
-
"h3": "^2.0.1-rc.
|
|
61
|
+
"h3": "^2.0.1-rc.5",
|
|
62
62
|
"jiti": "^2.6.1",
|
|
63
63
|
"nf3": "^0.1.2",
|
|
64
64
|
"ofetch": "^1.4.1",
|