lixnet 1.1.6 → 1.1.7
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/lib/server.js +12 -3
- package/package.json +1 -1
package/dist/lib/server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import LixnetLog from "./util/log";
|
|
3
3
|
export default class LixnetServer {
|
|
4
|
-
constructor({ debugLog = false, logger, jsonResponseMaker = Response.json, }) {
|
|
4
|
+
constructor({ debugLog = false, logger, jsonResponseMaker = (data, init) => Response.json(data, init), }) {
|
|
5
5
|
this.events = {};
|
|
6
6
|
this.logger = LixnetLog;
|
|
7
7
|
this.debugLog = false;
|
|
@@ -52,14 +52,23 @@ export default class LixnetServer {
|
|
|
52
52
|
? event.schema.parse(jsonData.input)
|
|
53
53
|
: jsonData.input;
|
|
54
54
|
try {
|
|
55
|
+
let additionalInit = {};
|
|
56
|
+
const newRequest = {
|
|
57
|
+
...request,
|
|
58
|
+
setAdditionalInit: (init) => {
|
|
59
|
+
additionalInit = init;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
55
62
|
const result = await event.handler({
|
|
56
|
-
request,
|
|
63
|
+
request: newRequest,
|
|
57
64
|
...validatedInput,
|
|
58
65
|
});
|
|
59
66
|
if (result instanceof Response) {
|
|
60
67
|
return result;
|
|
61
68
|
}
|
|
62
|
-
return this.jsonResponseMaker({
|
|
69
|
+
return this.jsonResponseMaker({
|
|
70
|
+
data: result.headers,
|
|
71
|
+
}, additionalInit);
|
|
63
72
|
}
|
|
64
73
|
catch (error) {
|
|
65
74
|
return this.jsonResponseMaker({
|