@autofleet/super-express 1.1.21-beta-3 → 2.0.0
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/index.js +16 -35
- package/package.json +11 -8
package/index.js
CHANGED
@@ -1,46 +1,27 @@
|
|
1
|
-
|
1
|
+
import express from 'express';
|
2
|
+
import helmet from 'helmet';
|
3
|
+
import morgan from 'morgan';
|
2
4
|
|
3
|
-
|
5
|
+
import defaultOptions from './default-options.json';
|
4
6
|
|
5
|
-
|
6
|
-
const
|
7
|
-
const
|
7
|
+
export default function(options = {}) {
|
8
|
+
const app = express(options);
|
9
|
+
const isProd = process.env.NODE_ENV === 'production';
|
10
|
+
const mergedOptions = Object.assign({}, defaultOptions, options);
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
const isProd = process.env.NODE_ENV === 'production'
|
15
|
-
const isStage = process.env.NODE_ENV === 'staging'
|
16
|
-
const mergedOptions = Object.assign({}, defaultOptions, options)
|
17
|
-
|
18
|
-
if (options.httpLogCb) {
|
19
|
-
app.use(morgan((tokens, req, res) => {
|
20
|
-
options.httpLogCb({
|
21
|
-
method: tokens.method(req, res),
|
22
|
-
url: tokens.url(req, res),
|
23
|
-
status: tokens.status(req, res),
|
24
|
-
'content-length': tokens.res(req, res, 'content-length'),
|
25
|
-
'response-time': tokens['response-time'](req, res),
|
26
|
-
'user-agent': tokens['user-agent'](req, res),
|
27
|
-
})
|
28
|
-
}))
|
12
|
+
app.use(morgan(':method :url :status :res[content-length] - :response-time ms'));
|
13
|
+
app.use(helmet());
|
14
|
+
if (mergedOptions.bodyParser) {
|
15
|
+
app.use(express.json({ limit: '1000mb' }))
|
29
16
|
} else {
|
30
|
-
|
31
|
-
}
|
32
|
-
|
33
|
-
// General
|
34
|
-
// app.use(helmet());
|
35
|
-
if( mergedOptions.bodyParser ) {
|
36
|
-
app.use(bodyParser.json({ limit: '1000mb' }))
|
17
|
+
console.log('[SuperExpress] Body parser is disabled');
|
37
18
|
}
|
38
19
|
|
39
20
|
app.nativeListen = app.listen
|
40
21
|
app.listen = function (port, cb) {
|
41
|
-
console.log(
|
42
|
-
console.log(
|
43
|
-
|
22
|
+
console.log(`[SuperExpress] will listen on port ${port}`);
|
23
|
+
console.log(`[SuperExpress] Production mode: ${isProd}`);
|
24
|
+
app.nativeListen(port, cb)
|
44
25
|
}
|
45
26
|
|
46
27
|
return app
|
package/package.json
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
{
|
2
2
|
"name": "@autofleet/super-express",
|
3
|
-
"version": "
|
3
|
+
"version": "2.0.0",
|
4
4
|
"description": "AF Express with built in boilerplate",
|
5
5
|
"main": "index.js",
|
6
|
-
"
|
6
|
+
"type": "module",
|
7
|
+
"author": "Autofleet",
|
7
8
|
"license": "MIT",
|
8
9
|
"dependencies": {
|
9
|
-
"
|
10
|
-
"
|
11
|
-
"
|
12
|
-
"helmet": "^4.6.0",
|
13
|
-
"morgan": "^1.10.0"
|
10
|
+
"express": "^4.19.2",
|
11
|
+
"helmet": "^3.21.2",
|
12
|
+
"morgan": "^1.9.1"
|
14
13
|
},
|
15
14
|
"scripts": {
|
16
15
|
"test": "echo \"Error: no test specified\" && exit 1"
|
@@ -22,5 +21,9 @@
|
|
22
21
|
"bugs": {
|
23
22
|
"url": "https://github.com/Autofleet/super-express/issues"
|
24
23
|
},
|
25
|
-
"homepage": "https://github.com/Autofleet/super-express#readme"
|
24
|
+
"homepage": "https://github.com/Autofleet/super-express#readme",
|
25
|
+
"devDependencies": {
|
26
|
+
"@types/express": "^4.17.21",
|
27
|
+
"@types/helmet": "^4.0.0"
|
28
|
+
}
|
26
29
|
}
|