@aeriajs/node-http 0.0.160 → 0.0.162
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/driver.d.ts +2 -3
- package/dist/driver.js +14 -4
- package/dist/driver.mjs +14 -4
- package/package.json +3 -3
package/dist/driver.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { GenericRequest, GenericResponse } from '@aeriajs/types';
|
|
2
|
-
import type { ServerOptions } from '@aeriajs/http';
|
|
1
|
+
import type { GenericRequest, GenericResponse, ServerOptions } from '@aeriajs/types';
|
|
3
2
|
import * as http from 'node:http';
|
|
4
3
|
export declare const abstractRequest: (request: http.IncomingMessage) => Promise<GenericRequest>;
|
|
5
|
-
export declare const abstractResponse: (response: http.ServerResponse) => GenericResponse;
|
|
4
|
+
export declare const abstractResponse: (response: http.ServerResponse, options: ServerOptions) => GenericResponse;
|
|
6
5
|
export declare const registerServer: (options: ServerOptions, cb: (req: GenericRequest, res: GenericResponse) => void | Promise<void>) => {
|
|
7
6
|
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
8
7
|
listen: () => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
package/dist/driver.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerServer = exports.abstractResponse = exports.abstractRequest = void 0;
|
|
4
|
+
const http_1 = require("@aeriajs/http");
|
|
4
5
|
const types_1 = require("@aeriajs/types");
|
|
5
6
|
const common_1 = require("@aeriajs/common");
|
|
6
7
|
const http = require("node:http");
|
|
@@ -33,13 +34,16 @@ const abstractRequest = async (request) => {
|
|
|
33
34
|
return req;
|
|
34
35
|
};
|
|
35
36
|
exports.abstractRequest = abstractRequest;
|
|
36
|
-
const abstractResponse = (response) => {
|
|
37
|
+
const abstractResponse = (response, options) => {
|
|
37
38
|
const { end } = response;
|
|
38
39
|
return Object.assign(response, {
|
|
39
40
|
writeHead: response.writeHead.bind(response),
|
|
40
41
|
setHeader: response.setHeader.bind(response),
|
|
41
42
|
end: (value) => {
|
|
42
43
|
if (value === undefined) {
|
|
44
|
+
if (options.enableLogging) {
|
|
45
|
+
(0, http_1.logResponse)(response);
|
|
46
|
+
}
|
|
43
47
|
return end.bind(response)();
|
|
44
48
|
}
|
|
45
49
|
if (typeof value === 'object' && !(value instanceof Buffer)) {
|
|
@@ -59,19 +63,25 @@ const abstractResponse = (response) => {
|
|
|
59
63
|
});
|
|
60
64
|
}
|
|
61
65
|
}
|
|
66
|
+
if (options.enableLogging) {
|
|
67
|
+
(0, http_1.logResponse)(response);
|
|
68
|
+
}
|
|
62
69
|
return end.bind(response)(JSON.stringify(value));
|
|
63
70
|
}
|
|
64
71
|
const endVal = value instanceof Buffer
|
|
65
72
|
? value
|
|
66
73
|
: String(value);
|
|
74
|
+
if (options.enableLogging) {
|
|
75
|
+
(0, http_1.logResponse)(response);
|
|
76
|
+
}
|
|
67
77
|
return end.bind(response)(endVal);
|
|
68
78
|
},
|
|
69
79
|
});
|
|
70
80
|
};
|
|
71
81
|
exports.abstractResponse = abstractResponse;
|
|
72
|
-
const abstractTransaction = async ($req, $res) => {
|
|
82
|
+
const abstractTransaction = async ($req, $res, options) => {
|
|
73
83
|
const req = await (0, exports.abstractRequest)($req);
|
|
74
|
-
const res = (0, exports.abstractResponse)($res);
|
|
84
|
+
const res = (0, exports.abstractResponse)($res, options);
|
|
75
85
|
return {
|
|
76
86
|
req,
|
|
77
87
|
res,
|
|
@@ -79,7 +89,7 @@ const abstractTransaction = async ($req, $res) => {
|
|
|
79
89
|
};
|
|
80
90
|
const registerServer = (options, cb) => {
|
|
81
91
|
const server = http.createServer(async ($req, $res) => {
|
|
82
|
-
const { req, res, } = await abstractTransaction($req, $res);
|
|
92
|
+
const { req, res, } = await abstractTransaction($req, $res, options);
|
|
83
93
|
cb(req, res);
|
|
84
94
|
});
|
|
85
95
|
return {
|
package/dist/driver.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
import { logResponse } from "@aeriajs/http";
|
|
2
3
|
import { ERROR_SYMBOL_DESCRIPTION } from "@aeriajs/types";
|
|
3
4
|
import { isEndpointError } from "@aeriajs/common";
|
|
4
5
|
import * as http from "node:http";
|
|
@@ -26,13 +27,16 @@ export const abstractRequest = async (request) => {
|
|
|
26
27
|
});
|
|
27
28
|
return req;
|
|
28
29
|
};
|
|
29
|
-
export const abstractResponse = (response) => {
|
|
30
|
+
export const abstractResponse = (response, options) => {
|
|
30
31
|
const { end } = response;
|
|
31
32
|
return Object.assign(response, {
|
|
32
33
|
writeHead: response.writeHead.bind(response),
|
|
33
34
|
setHeader: response.setHeader.bind(response),
|
|
34
35
|
end: (value) => {
|
|
35
36
|
if (value === void 0) {
|
|
37
|
+
if (options.enableLogging) {
|
|
38
|
+
logResponse(response);
|
|
39
|
+
}
|
|
36
40
|
return end.bind(response)();
|
|
37
41
|
}
|
|
38
42
|
if (typeof value === "object" && !(value instanceof Buffer)) {
|
|
@@ -51,16 +55,22 @@ export const abstractResponse = (response) => {
|
|
|
51
55
|
});
|
|
52
56
|
}
|
|
53
57
|
}
|
|
58
|
+
if (options.enableLogging) {
|
|
59
|
+
logResponse(response);
|
|
60
|
+
}
|
|
54
61
|
return end.bind(response)(JSON.stringify(value));
|
|
55
62
|
}
|
|
56
63
|
const endVal = value instanceof Buffer ? value : String(value);
|
|
64
|
+
if (options.enableLogging) {
|
|
65
|
+
logResponse(response);
|
|
66
|
+
}
|
|
57
67
|
return end.bind(response)(endVal);
|
|
58
68
|
}
|
|
59
69
|
});
|
|
60
70
|
};
|
|
61
|
-
const abstractTransaction = async ($req, $res) => {
|
|
71
|
+
const abstractTransaction = async ($req, $res, options) => {
|
|
62
72
|
const req = await abstractRequest($req);
|
|
63
|
-
const res = abstractResponse($res);
|
|
73
|
+
const res = abstractResponse($res, options);
|
|
64
74
|
return {
|
|
65
75
|
req,
|
|
66
76
|
res
|
|
@@ -71,7 +81,7 @@ export const registerServer = (options, cb) => {
|
|
|
71
81
|
const {
|
|
72
82
|
req,
|
|
73
83
|
res
|
|
74
|
-
} = await abstractTransaction($req, $res);
|
|
84
|
+
} = await abstractTransaction($req, $res, options);
|
|
75
85
|
cb(req, res);
|
|
76
86
|
});
|
|
77
87
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/node-http",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.162",
|
|
4
4
|
"description": "## Installation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"@aeriajs/http": "link:../http"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@aeriajs/common": "^0.0.
|
|
30
|
-
"@aeriajs/http": "^0.0.
|
|
29
|
+
"@aeriajs/common": "^0.0.134",
|
|
30
|
+
"@aeriajs/http": "^0.0.162"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"test": "echo skipping",
|