dx-server 0.5.8 → 0.5.10
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 +14 -16
- package/cjs/bodyHelpers.d.ts +2 -3
- package/esm/bodyHelpers.d.ts +2 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -119,22 +119,20 @@ const serverChain = chain(
|
|
|
119
119
|
app.use('/public', express.static('public'))
|
|
120
120
|
}),
|
|
121
121
|
authContext.chain(), // chain context will set the context value to authContext.value in every request
|
|
122
|
-
router.post({// example of catching error for all /api/* routes
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}, {status: 500})
|
|
137
|
-
}
|
|
122
|
+
router.post('/api', async ({next}) => {// example of catching error for all /api/* routes
|
|
123
|
+
try {
|
|
124
|
+
await next()
|
|
125
|
+
} catch (e) {
|
|
126
|
+
if (e instanceof ServerError) setJson({// only app error message should be shown to user
|
|
127
|
+
error: e.message,
|
|
128
|
+
code: e.code,
|
|
129
|
+
}, {status: e.status})
|
|
130
|
+
else {// report system error
|
|
131
|
+
console.error(e)
|
|
132
|
+
setJson({
|
|
133
|
+
message: 'internal server error',
|
|
134
|
+
code: 'internal'
|
|
135
|
+
}, {status: 500})
|
|
138
136
|
}
|
|
139
137
|
}
|
|
140
138
|
}, {end: false}), // note: {end: false} is required to match all /api/* routes. This option is passed directly to path-to-regexp
|
package/cjs/bodyHelpers.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
3
|
import { IncomingMessage } from 'node:http';
|
|
4
|
-
import qs from 'qs';
|
|
5
4
|
export interface BufferBodyOptions {
|
|
6
5
|
bodyLimit: number;
|
|
7
6
|
simplifyUrlEncodedBody?: boolean;
|
|
@@ -12,6 +11,6 @@ export declare function bufferFromReq(req: IncomingMessage, options?: Partial<Bu
|
|
|
12
11
|
export declare function jsonFromReq(req: IncomingMessage, options?: Partial<BufferBodyOptions>): Promise<any>;
|
|
13
12
|
export declare function rawFromReq(req: IncomingMessage, options?: Partial<BufferBodyOptions>): Promise<Buffer | undefined>;
|
|
14
13
|
export declare function textFromReq(req: IncomingMessage, options?: Partial<BufferBodyOptions>): Promise<string | undefined>;
|
|
15
|
-
export declare function urlEncodedFromReq(req: IncomingMessage, options?: Partial<BufferBodyOptions>): Promise<
|
|
14
|
+
export declare function urlEncodedFromReq(req: IncomingMessage, options?: Partial<BufferBodyOptions>): Promise<any>;
|
|
16
15
|
export declare function urlFromReq(req: IncomingMessage): URL;
|
|
17
|
-
export declare function queryFromReq(req: IncomingMessage, options?: Partial<BufferBodyOptions>):
|
|
16
|
+
export declare function queryFromReq(req: IncomingMessage, options?: Partial<BufferBodyOptions>): any;
|
package/esm/bodyHelpers.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
3
|
import { IncomingMessage } from 'node:http';
|
|
4
|
-
import qs from 'qs';
|
|
5
4
|
export interface BufferBodyOptions {
|
|
6
5
|
bodyLimit: number;
|
|
7
6
|
simplifyUrlEncodedBody?: boolean;
|
|
@@ -12,6 +11,6 @@ export declare function bufferFromReq(req: IncomingMessage, options?: Partial<Bu
|
|
|
12
11
|
export declare function jsonFromReq(req: IncomingMessage, options?: Partial<BufferBodyOptions>): Promise<any>;
|
|
13
12
|
export declare function rawFromReq(req: IncomingMessage, options?: Partial<BufferBodyOptions>): Promise<Buffer | undefined>;
|
|
14
13
|
export declare function textFromReq(req: IncomingMessage, options?: Partial<BufferBodyOptions>): Promise<string | undefined>;
|
|
15
|
-
export declare function urlEncodedFromReq(req: IncomingMessage, options?: Partial<BufferBodyOptions>): Promise<
|
|
14
|
+
export declare function urlEncodedFromReq(req: IncomingMessage, options?: Partial<BufferBodyOptions>): Promise<any>;
|
|
16
15
|
export declare function urlFromReq(req: IncomingMessage): URL;
|
|
17
|
-
export declare function queryFromReq(req: IncomingMessage, options?: Partial<BufferBodyOptions>):
|
|
16
|
+
export declare function queryFromReq(req: IncomingMessage, options?: Partial<BufferBodyOptions>): any;
|