@nattyjs/express 0.0.1-beta.70 → 0.0.1-beta.72
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/index.cjs +18 -5
- package/dist/index.mjs +19 -6
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -18,8 +18,9 @@ const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
|
18
18
|
|
|
19
19
|
async function getRequestBodyInfo(request) {
|
|
20
20
|
const contentType = request.headers["content-type"];
|
|
21
|
+
const requestMethod = request.method?.toLowerCase();
|
|
21
22
|
const bodyInfo = {};
|
|
22
|
-
if (
|
|
23
|
+
if (requestMethod !== common.GET) {
|
|
23
24
|
if (contentType && contentType.toLowerCase().indexOf("application/json") > -1)
|
|
24
25
|
bodyInfo.json = request.body;
|
|
25
26
|
}
|
|
@@ -68,14 +69,26 @@ function parseCookies(value) {
|
|
|
68
69
|
return jsonCookies;
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
function getHeaderValue(request, name) {
|
|
73
|
+
if (typeof request.get === "function") {
|
|
74
|
+
return request.get(name) || void 0;
|
|
75
|
+
}
|
|
76
|
+
const headerValue = request.headers?.[name.toLowerCase()];
|
|
77
|
+
return Array.isArray(headerValue) ? headerValue[0] : headerValue;
|
|
78
|
+
}
|
|
79
|
+
function buildRequestUrl(request) {
|
|
80
|
+
const requestPath = request.originalUrl || request.url || "/";
|
|
81
|
+
const host = getHeaderValue(request, "host");
|
|
82
|
+
const protocol = request.protocol || "http";
|
|
83
|
+
const origin = host ? `${protocol}://${host}` : "http://127.0.0.1";
|
|
84
|
+
return new URL(requestPath, origin).toString();
|
|
85
|
+
}
|
|
71
86
|
function requestHandler(config) {
|
|
72
87
|
return async (request, response) => {
|
|
73
88
|
const httpHandler = new core.HttpHandler();
|
|
74
|
-
const apiPrefix = `/${common.commonContainer.nattyConfig.api?.rootPath}`;
|
|
75
|
-
const url = config.framework == common.FrameworkType.Firebase ? `http://localhost:3000/api${request.url}` : `http://localhost:3000${apiPrefix}${request.url}`;
|
|
76
89
|
const httpContext = new core.HttpContext(
|
|
77
90
|
{
|
|
78
|
-
url,
|
|
91
|
+
url: buildRequestUrl(request),
|
|
79
92
|
method: request.method,
|
|
80
93
|
body: await getRequestBodyInfo(request),
|
|
81
94
|
headers: request.headers,
|
|
@@ -197,7 +210,7 @@ const ExpressModule = {
|
|
|
197
210
|
});
|
|
198
211
|
}
|
|
199
212
|
}
|
|
200
|
-
app.use(apiPrefix, requestHandler(
|
|
213
|
+
app.use(apiPrefix, requestHandler());
|
|
201
214
|
if (config.autoGeneratePort == true || config.autoGeneratePort == void 0)
|
|
202
215
|
common.getPort().then((port) => {
|
|
203
216
|
app.listen(port, () => {
|
package/dist/index.mjs
CHANGED
|
@@ -3,13 +3,14 @@ import path from 'node:path';
|
|
|
3
3
|
import cors from 'cors';
|
|
4
4
|
import compression from 'compression';
|
|
5
5
|
import { HttpHandler, HttpContext } from '@nattyjs/core';
|
|
6
|
-
import { GET, commonContainer,
|
|
6
|
+
import { GET, commonContainer, getPort } from '@nattyjs/common';
|
|
7
7
|
import fs from 'node:fs';
|
|
8
8
|
|
|
9
9
|
async function getRequestBodyInfo(request) {
|
|
10
10
|
const contentType = request.headers["content-type"];
|
|
11
|
+
const requestMethod = request.method?.toLowerCase();
|
|
11
12
|
const bodyInfo = {};
|
|
12
|
-
if (
|
|
13
|
+
if (requestMethod !== GET) {
|
|
13
14
|
if (contentType && contentType.toLowerCase().indexOf("application/json") > -1)
|
|
14
15
|
bodyInfo.json = request.body;
|
|
15
16
|
}
|
|
@@ -58,14 +59,26 @@ function parseCookies(value) {
|
|
|
58
59
|
return jsonCookies;
|
|
59
60
|
}
|
|
60
61
|
|
|
62
|
+
function getHeaderValue(request, name) {
|
|
63
|
+
if (typeof request.get === "function") {
|
|
64
|
+
return request.get(name) || void 0;
|
|
65
|
+
}
|
|
66
|
+
const headerValue = request.headers?.[name.toLowerCase()];
|
|
67
|
+
return Array.isArray(headerValue) ? headerValue[0] : headerValue;
|
|
68
|
+
}
|
|
69
|
+
function buildRequestUrl(request) {
|
|
70
|
+
const requestPath = request.originalUrl || request.url || "/";
|
|
71
|
+
const host = getHeaderValue(request, "host");
|
|
72
|
+
const protocol = request.protocol || "http";
|
|
73
|
+
const origin = host ? `${protocol}://${host}` : "http://127.0.0.1";
|
|
74
|
+
return new URL(requestPath, origin).toString();
|
|
75
|
+
}
|
|
61
76
|
function requestHandler(config) {
|
|
62
77
|
return async (request, response) => {
|
|
63
78
|
const httpHandler = new HttpHandler();
|
|
64
|
-
const apiPrefix = `/${commonContainer.nattyConfig.api?.rootPath}`;
|
|
65
|
-
const url = config.framework == FrameworkType.Firebase ? `http://localhost:3000/api${request.url}` : `http://localhost:3000${apiPrefix}${request.url}`;
|
|
66
79
|
const httpContext = new HttpContext(
|
|
67
80
|
{
|
|
68
|
-
url,
|
|
81
|
+
url: buildRequestUrl(request),
|
|
69
82
|
method: request.method,
|
|
70
83
|
body: await getRequestBodyInfo(request),
|
|
71
84
|
headers: request.headers,
|
|
@@ -187,7 +200,7 @@ const ExpressModule = {
|
|
|
187
200
|
});
|
|
188
201
|
}
|
|
189
202
|
}
|
|
190
|
-
app.use(apiPrefix, requestHandler(
|
|
203
|
+
app.use(apiPrefix, requestHandler());
|
|
191
204
|
if (config.autoGeneratePort == true || config.autoGeneratePort == void 0)
|
|
192
205
|
getPort().then((port) => {
|
|
193
206
|
app.listen(port, () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nattyjs/express",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.72",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "ajayojha <ojhaajay@outlook.com>",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"chokidar": "4.0.3",
|
|
20
20
|
"cors": "2.8.5",
|
|
21
21
|
"compression": "1.7.4",
|
|
22
|
-
"@nattyjs/core": "0.0.1-beta.
|
|
23
|
-
"@nattyjs/common": "0.0.1-beta.
|
|
24
|
-
"@nattyjs/types": "0.0.1-beta.
|
|
22
|
+
"@nattyjs/core": "0.0.1-beta.72",
|
|
23
|
+
"@nattyjs/common": "0.0.1-beta.72",
|
|
24
|
+
"@nattyjs/types": "0.0.1-beta.72"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "20.3.1",
|