@nattyjs/express 0.0.1-beta.1 → 0.0.1-beta.11
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 +30 -28
- package/dist/index.mjs +31 -29
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -55,41 +55,43 @@ function parseCookies(value) {
|
|
|
55
55
|
return jsonCookies;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
58
|
+
function requestHandler(config) {
|
|
59
|
+
return async (request, response) => {
|
|
60
|
+
const httpHandler = new core.HttpHandler();
|
|
61
|
+
const url = config.framework == common.FrameworkType.Firebase ? `http://localhost:3000/api${request.url}` : `http://localhost:3000${request.url}`;
|
|
62
|
+
const httpContext = new core.HttpContext(
|
|
63
|
+
{
|
|
64
|
+
url,
|
|
65
|
+
method: request.method,
|
|
66
|
+
body: await getRequestBodyInfo(request),
|
|
67
|
+
headers: request.headers,
|
|
68
|
+
cookies: parseCookies(request.headers["cookie"])
|
|
69
|
+
},
|
|
70
|
+
response
|
|
71
|
+
);
|
|
72
|
+
return httpHandler.processRequest(httpContext).then((httpResponse) => {
|
|
73
|
+
return getResponse(response, httpResponse);
|
|
74
|
+
}).catch((t) => {
|
|
75
|
+
response.send();
|
|
76
|
+
});
|
|
77
|
+
};
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
const app = express__default();
|
|
78
81
|
const ExpressModule = {
|
|
79
82
|
init(config) {
|
|
80
83
|
app.use(compression__default());
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
|
|
84
|
-
"preflightContinue": false,
|
|
85
|
-
"optionsSuccessStatus": 204,
|
|
86
|
-
"credentials": true
|
|
87
|
-
}));
|
|
84
|
+
if (config.cors)
|
|
85
|
+
app.use(cors__default(config.cors));
|
|
88
86
|
app.use(express__default.json());
|
|
89
|
-
app.all("*", requestHandler);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
app.all("*", requestHandler(config));
|
|
88
|
+
if (config.autoGeneratePort == true || config.autoGeneratePort == void 0)
|
|
89
|
+
common.getPort().then((port) => {
|
|
90
|
+
app.listen(port, () => {
|
|
91
|
+
console.log(`[NATTYJS]:Server is running on port ${port}`);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
return app;
|
|
93
95
|
}
|
|
94
96
|
};
|
|
95
97
|
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import express from 'express';
|
|
|
2
2
|
import cors from 'cors';
|
|
3
3
|
import compression from 'compression';
|
|
4
4
|
import { HttpHandler, HttpContext } from '@nattyjs/core';
|
|
5
|
-
import { GET } from '@nattyjs/common';
|
|
5
|
+
import { GET, FrameworkType, getPort } from '@nattyjs/common';
|
|
6
6
|
|
|
7
7
|
async function getRequestBodyInfo(request) {
|
|
8
8
|
const contentType = request.headers["content-type"];
|
|
@@ -47,41 +47,43 @@ function parseCookies(value) {
|
|
|
47
47
|
return jsonCookies;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
{
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
50
|
+
function requestHandler(config) {
|
|
51
|
+
return async (request, response) => {
|
|
52
|
+
const httpHandler = new HttpHandler();
|
|
53
|
+
const url = config.framework == FrameworkType.Firebase ? `http://localhost:3000/api${request.url}` : `http://localhost:3000${request.url}`;
|
|
54
|
+
const httpContext = new HttpContext(
|
|
55
|
+
{
|
|
56
|
+
url,
|
|
57
|
+
method: request.method,
|
|
58
|
+
body: await getRequestBodyInfo(request),
|
|
59
|
+
headers: request.headers,
|
|
60
|
+
cookies: parseCookies(request.headers["cookie"])
|
|
61
|
+
},
|
|
62
|
+
response
|
|
63
|
+
);
|
|
64
|
+
return httpHandler.processRequest(httpContext).then((httpResponse) => {
|
|
65
|
+
return getResponse(response, httpResponse);
|
|
66
|
+
}).catch((t) => {
|
|
67
|
+
response.send();
|
|
68
|
+
});
|
|
69
|
+
};
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
const app = express();
|
|
70
73
|
const ExpressModule = {
|
|
71
74
|
init(config) {
|
|
72
75
|
app.use(compression());
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
|
|
76
|
-
"preflightContinue": false,
|
|
77
|
-
"optionsSuccessStatus": 204,
|
|
78
|
-
"credentials": true
|
|
79
|
-
}));
|
|
76
|
+
if (config.cors)
|
|
77
|
+
app.use(cors(config.cors));
|
|
80
78
|
app.use(express.json());
|
|
81
|
-
app.all("*", requestHandler);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
app.all("*", requestHandler(config));
|
|
80
|
+
if (config.autoGeneratePort == true || config.autoGeneratePort == void 0)
|
|
81
|
+
getPort().then((port) => {
|
|
82
|
+
app.listen(port, () => {
|
|
83
|
+
console.log(`[NATTYJS]:Server is running on port ${port}`);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
return app;
|
|
85
87
|
}
|
|
86
88
|
};
|
|
87
89
|
|
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.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "ajayojha <ojhaajay@outlook.com>",
|
|
@@ -18,8 +18,9 @@
|
|
|
18
18
|
"express": "4.18.2",
|
|
19
19
|
"cors": "2.8.5",
|
|
20
20
|
"compression": "1.7.4",
|
|
21
|
-
"@nattyjs/core": "0.0.1-beta.
|
|
22
|
-
"@nattyjs/
|
|
21
|
+
"@nattyjs/core": "0.0.1-beta.11",
|
|
22
|
+
"@nattyjs/common": "0.0.1-beta.11",
|
|
23
|
+
"@nattyjs/types": "0.0.1-beta.11"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@types/node": "20.3.1",
|