@server/next 0.27.12 → 0.28.0
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/index.d.ts +7 -4
- package/index.js +8 -3
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -82,6 +82,7 @@ type AuthSettings = {
|
|
|
82
82
|
cleanUser: <T = AuthUser>(user: T) => T | Promise<T>;
|
|
83
83
|
redirect: string;
|
|
84
84
|
};
|
|
85
|
+
type OnError = (error: Error, ctx: Context) => Response | Promise<Response>;
|
|
85
86
|
type Options = {
|
|
86
87
|
port?: number;
|
|
87
88
|
secret?: string;
|
|
@@ -96,6 +97,7 @@ type Options = {
|
|
|
96
97
|
cors?: CorsOptions;
|
|
97
98
|
auth?: AuthOption;
|
|
98
99
|
openapi?: any;
|
|
100
|
+
onError?: OnError;
|
|
99
101
|
};
|
|
100
102
|
type Settings = {
|
|
101
103
|
port: number;
|
|
@@ -111,6 +113,7 @@ type Settings = {
|
|
|
111
113
|
cors?: CorsSettings;
|
|
112
114
|
auth?: AuthSettings;
|
|
113
115
|
openapi?: any;
|
|
116
|
+
onError?: OnError;
|
|
114
117
|
};
|
|
115
118
|
type Time = {
|
|
116
119
|
(name: string): void;
|
|
@@ -228,10 +231,10 @@ declare class Router<O extends ServerConfig = object> {
|
|
|
228
231
|
patch<Path extends string>(path: Path, options: RouteOptions, ...middleware: Mids<O, Path>): this;
|
|
229
232
|
patch(...middleware: Middleware<O>[]): this;
|
|
230
233
|
patch(options: RouteOptions, ...middleware: Middleware<O>[]): this;
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
234
|
+
delete<Path extends string>(path: Path, ...middleware: Mids<O, Path>): this;
|
|
235
|
+
delete<Path extends string>(path: Path, options: RouteOptions, ...middleware: Mids<O, Path>): this;
|
|
236
|
+
delete(...middleware: Middleware<O>[]): this;
|
|
237
|
+
delete(options: RouteOptions, ...middleware: Middleware<O>[]): this;
|
|
235
238
|
options<Path extends string>(path: Path, ...middleware: Mids<O, Path>): this;
|
|
236
239
|
options<Path extends string>(path: Path, options: RouteOptions, ...mid: Mids<O, Path>): this;
|
|
237
240
|
options(...middleware: Middleware<O>[]): this;
|
package/index.js
CHANGED
|
@@ -662,6 +662,11 @@ function config(options = {}) {
|
|
|
662
662
|
settings.openapi = {};
|
|
663
663
|
}
|
|
664
664
|
}
|
|
665
|
+
settings.onError = options.onError || ((error) => {
|
|
666
|
+
return new Response(error.message || "Server Error", {
|
|
667
|
+
status: error.status || 500
|
|
668
|
+
});
|
|
669
|
+
});
|
|
665
670
|
return settings;
|
|
666
671
|
}
|
|
667
672
|
|
|
@@ -973,9 +978,9 @@ async function handleRequest(handlers, ctx) {
|
|
|
973
978
|
if (method !== "*") break;
|
|
974
979
|
}
|
|
975
980
|
if (ctx.platform.provider === "netlify") return;
|
|
976
|
-
|
|
981
|
+
throw new ServerError_default("NOT_FOUND", 404, "Not Found");
|
|
977
982
|
} catch (error) {
|
|
978
|
-
return
|
|
983
|
+
return ctx.options.onError(error, ctx);
|
|
979
984
|
}
|
|
980
985
|
}
|
|
981
986
|
|
|
@@ -1845,7 +1850,7 @@ var Router = class _Router {
|
|
|
1845
1850
|
}
|
|
1846
1851
|
return this.handle("patch", pathOrMid, ...middleware);
|
|
1847
1852
|
}
|
|
1848
|
-
|
|
1853
|
+
delete(pathOrMid, optionsOrMid, ...middleware) {
|
|
1849
1854
|
if (typeof pathOrMid === "string" && isMiddleware(optionsOrMid)) {
|
|
1850
1855
|
return this.handle("delete", pathOrMid, optionsOrMid, ...middleware);
|
|
1851
1856
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@server/next",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
|
|
5
5
|
"homepage": "https://server-js.com/",
|
|
6
6
|
"repository": "https://github.com/franciscop/server-next.git",
|