@nattyjs/express 0.0.1-beta.31 → 0.0.1-beta.33
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 +44 -7
- package/dist/index.mjs +30 -7
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -5,22 +5,37 @@ const cors = require('cors');
|
|
|
5
5
|
const compression = require('compression');
|
|
6
6
|
const core = require('@nattyjs/core');
|
|
7
7
|
const common = require('@nattyjs/common');
|
|
8
|
+
const chokidar = require('chokidar');
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const path = require('path');
|
|
8
11
|
|
|
9
12
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
10
13
|
|
|
14
|
+
function _interopNamespaceCompat(e) {
|
|
15
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
16
|
+
const n = Object.create(null);
|
|
17
|
+
if (e) {
|
|
18
|
+
for (const k in e) {
|
|
19
|
+
n[k] = e[k];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return n;
|
|
24
|
+
}
|
|
25
|
+
|
|
11
26
|
const express__default = /*#__PURE__*/_interopDefaultCompat(express);
|
|
12
27
|
const cors__default = /*#__PURE__*/_interopDefaultCompat(cors);
|
|
13
28
|
const compression__default = /*#__PURE__*/_interopDefaultCompat(compression);
|
|
29
|
+
const chokidar__default = /*#__PURE__*/_interopDefaultCompat(chokidar);
|
|
30
|
+
const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
|
|
14
31
|
|
|
15
32
|
async function getRequestBodyInfo(request) {
|
|
16
33
|
const contentType = request.headers["content-type"];
|
|
17
34
|
const bodyInfo = {};
|
|
18
|
-
if (request.method !== common.GET)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
35
|
+
if (request.method !== common.GET) {
|
|
36
|
+
if (contentType && contentType.toLowerCase().indexOf("application/json") > -1)
|
|
37
|
+
bodyInfo.json = request.body;
|
|
38
|
+
}
|
|
24
39
|
return bodyInfo;
|
|
25
40
|
}
|
|
26
41
|
|
|
@@ -81,6 +96,27 @@ function requestHandler(config) {
|
|
|
81
96
|
};
|
|
82
97
|
}
|
|
83
98
|
|
|
99
|
+
function watchDirectoryPath() {
|
|
100
|
+
const packageJson = fs.readFileSync("./package.json", "utf-8");
|
|
101
|
+
const json = JSON.parse(packageJson);
|
|
102
|
+
const directoryPath = path__namespace.dirname(json.main);
|
|
103
|
+
return directoryPath;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function changeDetection(onAddOrChange) {
|
|
107
|
+
const watcher = chokidar__default.watch(watchDirectoryPath(), {
|
|
108
|
+
ignored: (file, stats) => stats?.isFile() && !file.endsWith(".js"),
|
|
109
|
+
ignoreInitial: true,
|
|
110
|
+
awaitWriteFinish: {
|
|
111
|
+
stabilityThreshold: 50,
|
|
112
|
+
pollInterval: 10
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
for (const type of ["add", "change"]) {
|
|
116
|
+
watcher.on(type, async () => onAddOrChange());
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
84
120
|
const app = express__default();
|
|
85
121
|
const ExpressModule = {
|
|
86
122
|
init(config) {
|
|
@@ -91,8 +127,9 @@ const ExpressModule = {
|
|
|
91
127
|
app.all("*", requestHandler(config));
|
|
92
128
|
if (config.autoGeneratePort == true || config.autoGeneratePort == void 0)
|
|
93
129
|
common.getPort().then((port) => {
|
|
94
|
-
app.listen(port, () => {
|
|
130
|
+
const server = app.listen(port, () => {
|
|
95
131
|
console.log(`[NATTYJS]:Server is running on port ${port}`);
|
|
132
|
+
changeDetection(() => server.close());
|
|
96
133
|
});
|
|
97
134
|
});
|
|
98
135
|
return app;
|
package/dist/index.mjs
CHANGED
|
@@ -3,16 +3,17 @@ import cors from 'cors';
|
|
|
3
3
|
import compression from 'compression';
|
|
4
4
|
import { HttpHandler, HttpContext } from '@nattyjs/core';
|
|
5
5
|
import { GET, FrameworkType, getPort } from '@nattyjs/common';
|
|
6
|
+
import chokidar from 'chokidar';
|
|
7
|
+
import { readFileSync } from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
6
9
|
|
|
7
10
|
async function getRequestBodyInfo(request) {
|
|
8
11
|
const contentType = request.headers["content-type"];
|
|
9
12
|
const bodyInfo = {};
|
|
10
|
-
if (request.method !== GET)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
break;
|
|
15
|
-
}
|
|
13
|
+
if (request.method !== GET) {
|
|
14
|
+
if (contentType && contentType.toLowerCase().indexOf("application/json") > -1)
|
|
15
|
+
bodyInfo.json = request.body;
|
|
16
|
+
}
|
|
16
17
|
return bodyInfo;
|
|
17
18
|
}
|
|
18
19
|
|
|
@@ -73,6 +74,27 @@ function requestHandler(config) {
|
|
|
73
74
|
};
|
|
74
75
|
}
|
|
75
76
|
|
|
77
|
+
function watchDirectoryPath() {
|
|
78
|
+
const packageJson = readFileSync("./package.json", "utf-8");
|
|
79
|
+
const json = JSON.parse(packageJson);
|
|
80
|
+
const directoryPath = path.dirname(json.main);
|
|
81
|
+
return directoryPath;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function changeDetection(onAddOrChange) {
|
|
85
|
+
const watcher = chokidar.watch(watchDirectoryPath(), {
|
|
86
|
+
ignored: (file, stats) => stats?.isFile() && !file.endsWith(".js"),
|
|
87
|
+
ignoreInitial: true,
|
|
88
|
+
awaitWriteFinish: {
|
|
89
|
+
stabilityThreshold: 50,
|
|
90
|
+
pollInterval: 10
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
for (const type of ["add", "change"]) {
|
|
94
|
+
watcher.on(type, async () => onAddOrChange());
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
76
98
|
const app = express();
|
|
77
99
|
const ExpressModule = {
|
|
78
100
|
init(config) {
|
|
@@ -83,8 +105,9 @@ const ExpressModule = {
|
|
|
83
105
|
app.all("*", requestHandler(config));
|
|
84
106
|
if (config.autoGeneratePort == true || config.autoGeneratePort == void 0)
|
|
85
107
|
getPort().then((port) => {
|
|
86
|
-
app.listen(port, () => {
|
|
108
|
+
const server = app.listen(port, () => {
|
|
87
109
|
console.log(`[NATTYJS]:Server is running on port ${port}`);
|
|
110
|
+
changeDetection(() => server.close());
|
|
88
111
|
});
|
|
89
112
|
});
|
|
90
113
|
return app;
|
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.33",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "ajayojha <ojhaajay@outlook.com>",
|
|
@@ -16,11 +16,12 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"express": "4.18.2",
|
|
19
|
+
"chokidar": "4.0.3",
|
|
19
20
|
"cors": "2.8.5",
|
|
20
21
|
"compression": "1.7.4",
|
|
21
|
-
"@nattyjs/core": "0.0.1-beta.
|
|
22
|
-
"@nattyjs/common": "0.0.1-beta.
|
|
23
|
-
"@nattyjs/types": "0.0.1-beta.
|
|
22
|
+
"@nattyjs/core": "0.0.1-beta.33",
|
|
23
|
+
"@nattyjs/common": "0.0.1-beta.33",
|
|
24
|
+
"@nattyjs/types": "0.0.1-beta.33"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@types/node": "20.3.1",
|