@stanlemon/server 0.3.26 → 0.3.28
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/eslint.config.js +1 -0
- package/package.json +5 -5
- package/src/asyncJsonHandler.js +1 -3
- package/src/createAppServer.js +12 -7
- package/src/schemaHandler.js +3 -3
- package/.eslintrc.json +0 -5
package/eslint.config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "@stanlemon/eslint-config";
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stanlemon/server",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.28",
|
|
4
4
|
"description": "A basic express web server setup.",
|
|
5
5
|
"author": "Stan Lemon <stanlemon@users.noreply.github.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
8
|
+
"node": ">=20.0"
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
11
|
"main": "./src/index.js",
|
|
12
12
|
"exports": "./src/index.js",
|
|
13
13
|
"scripts": {
|
|
14
14
|
"start": "NODE_ENV=development nodemon ./app.js",
|
|
15
|
-
"lint": "eslint
|
|
16
|
-
"lint:fix": "eslint --fix
|
|
15
|
+
"lint": "eslint .",
|
|
16
|
+
"lint:fix": "eslint --fix .",
|
|
17
17
|
"test": "jest --detectOpenHandles",
|
|
18
18
|
"test:coverage": "jest --detectOpenHandles --coverage",
|
|
19
19
|
"test:watch": "jest --detectOpenHandles --watch"
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@stanlemon/eslint-config": "*",
|
|
38
|
-
"@types/lodash": "^4.17.
|
|
38
|
+
"@types/lodash": "^4.17.9",
|
|
39
39
|
"nodemon": "^3.1.7"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/asyncJsonHandler.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isPlainObject } from "lodash-es";
|
|
2
|
-
import { formatInput } from "./index.js";
|
|
3
|
-
import { formatOutput } from "./index.js";
|
|
2
|
+
import { formatInput, formatOutput } from "./index.js";
|
|
4
3
|
|
|
5
4
|
export default asyncJsonHandler;
|
|
6
5
|
|
|
@@ -46,7 +45,6 @@ export function asyncJsonHandler(fn) {
|
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
if (process.env.NODE_ENV !== "production") {
|
|
49
|
-
// eslint-disable-next-line no-console
|
|
50
48
|
console.error(ex);
|
|
51
49
|
|
|
52
50
|
res.status(500).json({ error: formatError(ex) });
|
package/src/createAppServer.js
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import express, {
|
|
1
|
+
import { config } from "dotenv";
|
|
2
|
+
import express, {
|
|
3
|
+
Router,
|
|
4
|
+
json,
|
|
5
|
+
urlencoded,
|
|
6
|
+
static as serveStatic,
|
|
7
|
+
} from "express";
|
|
3
8
|
import cookieParser from "cookie-parser";
|
|
4
9
|
import compression from "compression";
|
|
5
10
|
import helmet from "helmet";
|
|
6
11
|
import morgan from "morgan";
|
|
7
|
-
import rateLimit from "express-rate-limit";
|
|
12
|
+
import { rateLimit } from "express-rate-limit";
|
|
8
13
|
import { createProxyMiddleware } from "http-proxy-middleware";
|
|
9
14
|
import path from "path";
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
config();
|
|
12
17
|
|
|
13
18
|
const NODE_ENV = process.env.NODE_ENV ?? "development";
|
|
14
19
|
|
|
@@ -38,8 +43,8 @@ export default function createAppServer(options) {
|
|
|
38
43
|
webpack !== false && NODE_ENV !== "production" && NODE_ENV !== "test";
|
|
39
44
|
|
|
40
45
|
const app = express();
|
|
41
|
-
app.use(
|
|
42
|
-
app.use(
|
|
46
|
+
app.use(urlencoded({ extended: true }));
|
|
47
|
+
app.use(json());
|
|
43
48
|
app.use(cookieParser());
|
|
44
49
|
|
|
45
50
|
if (NODE_ENV !== "test") {
|
|
@@ -94,7 +99,7 @@ export default function createAppServer(options) {
|
|
|
94
99
|
})
|
|
95
100
|
);
|
|
96
101
|
} else if (webpack !== false) {
|
|
97
|
-
app.use(
|
|
102
|
+
app.use(serveStatic("./dist"));
|
|
98
103
|
}
|
|
99
104
|
|
|
100
105
|
app.start = () => {
|
package/src/schemaHandler.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import asyncJsonHandler from "./asyncJsonHandler.js";
|
|
1
|
+
import { ValidationError } from "joi";
|
|
2
|
+
import { asyncJsonHandler } from "./asyncJsonHandler.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
@@ -39,7 +39,7 @@ export default function schemaHandler(schema, fn) {
|
|
|
39
39
|
// Wrap all of these in our async handler
|
|
40
40
|
await asyncJsonHandler(fn)(req, res, next);
|
|
41
41
|
} catch (error) {
|
|
42
|
-
if (error instanceof
|
|
42
|
+
if (error instanceof ValidationError) {
|
|
43
43
|
res.status(400).json({
|
|
44
44
|
errors: Object.assign.apply(
|
|
45
45
|
null,
|