@stanlemon/server 0.2.3 → 0.2.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/jest.config.js +1 -0
- package/package.json +8 -4
- package/src/asyncJsonHandler.js +1 -4
- package/src/convertCase.js +3 -3
- package/src/createAppServer.js +7 -2
- package/src/formatInput.js +2 -2
- package/src/formatOutput.js +2 -9
package/jest.config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "@stanlemon/webdev/jest.config.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stanlemon/server",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "A basic express web server setup.",
|
|
5
5
|
"author": "Stan Lemon <stanlemon@users.noreply.github.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,22 +14,26 @@
|
|
|
14
14
|
"start": "NODE_ENV=development nodemon ./app.js",
|
|
15
15
|
"lint": "eslint --ext js,jsx,ts,tsx ./",
|
|
16
16
|
"lint:format": "eslint --fix --ext js,jsx,ts,tsx ./",
|
|
17
|
-
"test": "
|
|
18
|
-
"test:
|
|
17
|
+
"test": "jest --detectOpenHandles",
|
|
18
|
+
"test:coverage": "jest --detectOpenHandles --coverage",
|
|
19
|
+
"test:watch": "jest --detectOpenHandles --watch"
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|
|
22
|
+
"@stanlemon/webdev": "*",
|
|
21
23
|
"compression": "^1.7.4",
|
|
22
|
-
"dotenv": "16.0.
|
|
24
|
+
"dotenv": "16.0.1",
|
|
23
25
|
"express": "^4.18.1",
|
|
24
26
|
"express-rate-limit": "^6.4.0",
|
|
25
27
|
"helmet": "^5.0.2",
|
|
26
28
|
"http-proxy-middleware": "^2.0.6",
|
|
27
29
|
"joi": "^17.6.0",
|
|
30
|
+
"lodash": "^4.17.21",
|
|
28
31
|
"lodash-es": "^4.17.21",
|
|
29
32
|
"morgan": "^1.10.0"
|
|
30
33
|
},
|
|
31
34
|
"devDependencies": {
|
|
32
35
|
"@stanlemon/eslint-config": "*",
|
|
36
|
+
"@types/lodash": "^4.14.182",
|
|
33
37
|
"nodemon": "^2.0.16"
|
|
34
38
|
}
|
|
35
39
|
}
|
package/src/asyncJsonHandler.js
CHANGED
|
@@ -37,10 +37,7 @@ export function asyncJsonHandler(fn) {
|
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
if (
|
|
41
|
-
process.env.NODE_ENV === "development" ||
|
|
42
|
-
process.env.NODE_ENV === "test"
|
|
43
|
-
) {
|
|
40
|
+
if (process.env.NODE_ENV !== "production") {
|
|
44
41
|
// eslint-disable-next-line no-console
|
|
45
42
|
console.error(ex);
|
|
46
43
|
|
package/src/convertCase.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isObject,
|
|
1
|
+
import { isObject, isString } from "lodash-es";
|
|
2
2
|
|
|
3
3
|
export default function convertCase(obj, me, convert) {
|
|
4
4
|
if (
|
|
@@ -8,9 +8,9 @@ export default function convertCase(obj, me, convert) {
|
|
|
8
8
|
)
|
|
9
9
|
) {
|
|
10
10
|
return new Date(obj);
|
|
11
|
-
} else if (isArray(obj)) {
|
|
11
|
+
} else if (Array.isArray(obj)) {
|
|
12
12
|
return obj.map((i) => me(i));
|
|
13
|
-
} else if (isObject(obj) && !isArray(obj)) {
|
|
13
|
+
} else if (isObject(obj) && !Array.isArray(obj)) {
|
|
14
14
|
const n = {};
|
|
15
15
|
Object.keys(obj).forEach((k) => (n[convert(k)] = me(obj[k])));
|
|
16
16
|
return n;
|
package/src/createAppServer.js
CHANGED
|
@@ -33,7 +33,11 @@ export default function createAppServer(options) {
|
|
|
33
33
|
app.use(helmet());
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
if (
|
|
36
|
+
if (
|
|
37
|
+
webpack !== false &&
|
|
38
|
+
process.env.NODE_ENV !== "production" &&
|
|
39
|
+
process.env.NODE_ENV !== "test"
|
|
40
|
+
) {
|
|
37
41
|
app.get(
|
|
38
42
|
"/*.js",
|
|
39
43
|
createProxyMiddleware({
|
|
@@ -68,7 +72,8 @@ export default function createAppServer(options) {
|
|
|
68
72
|
});
|
|
69
73
|
});
|
|
70
74
|
|
|
71
|
-
|
|
75
|
+
// If we're set to start. Btw we never start in test.
|
|
76
|
+
if (start && process.env.NODE_ENV !== "test") {
|
|
72
77
|
const server = app.listen(port);
|
|
73
78
|
|
|
74
79
|
/* eslint-disable no-console */
|
package/src/formatInput.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { snakeCase } from "lodash-es";
|
|
2
2
|
import convertCase from "./convertCase.js";
|
|
3
3
|
|
|
4
4
|
export default function formatInput(obj) {
|
|
5
|
-
if (isArray(obj)) {
|
|
5
|
+
if (Array.isArray(obj)) {
|
|
6
6
|
return obj.map((v) => formatInput(v));
|
|
7
7
|
}
|
|
8
8
|
return convertCase(obj, formatInput, snakeCase);
|
package/src/formatOutput.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
camelCase,
|
|
3
|
-
isPlainObject,
|
|
4
|
-
isArray,
|
|
5
|
-
isDate,
|
|
6
|
-
isEmpty,
|
|
7
|
-
omit,
|
|
8
|
-
} from "lodash-es";
|
|
1
|
+
import { camelCase, isPlainObject, isDate, isEmpty, omit } from "lodash-es";
|
|
9
2
|
import convertCase from "./convertCase.js";
|
|
10
3
|
|
|
11
4
|
export default function formatOutput(o, omittedFields = []) {
|
|
@@ -14,7 +7,7 @@ export default function formatOutput(o, omittedFields = []) {
|
|
|
14
7
|
if (isDate(obj)) {
|
|
15
8
|
return obj.toISOString();
|
|
16
9
|
}
|
|
17
|
-
if (isArray(obj)) {
|
|
10
|
+
if (Array.isArray(obj)) {
|
|
18
11
|
return obj.map((v) => formatOutput(v));
|
|
19
12
|
}
|
|
20
13
|
return convertCase(obj, formatOutput, camelCase);
|