Skip to content

Commit 4c35f1b

Browse files
committed
chore(deps): updates deps
1 parent 055233c commit 4c35f1b

9 files changed

+107
-56
lines changed

README.md

+22-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- [Installation](https://github.com/EQuimper/nodejs-api-boilerplate#installation)
3838
- [Install Mongodb](https://github.com/EQuimper/nodejs-api-boilerplate#install-mongodb)
3939
- [Raven Log](https://github.com/EQuimper/nodejs-api-boilerplate#raven-log)
40+
- [Body Whitelist](https://github.com/EQuimper/nodejs-api-boilerplate#body-whitelist)
4041
- [Api Doc](https://github.com/EQuimper/nodejs-api-boilerplate#api-doc)
4142
- [Pre-Commit Hook](https://github.com/EQuimper/nodejs-api-boilerplate#pre-commit-hook)
4243
- [Scripts](https://github.com/EQuimper/nodejs-api-boilerplate#scripts)
@@ -69,10 +70,28 @@ For get raven log create account here: [Sentry](https://sentry.io/)
6970

7071
---
7172

73+
## Body Whitelist
74+
75+
For security have add a whitelist function for your `req.body` coming from the front end. You can take a look of it in the `contants.js` file.
76+
77+
---
78+
7279
## Api Doc
7380

7481
Api doc his hosted on surge. [Link](http://equimper-nodejs-api-boilerplate.surge.sh/). For change the url and have your own docs just add you link in the `.env` file.
7582

83+
```js
84+
const WHITELIST = {
85+
posts: {
86+
create: ['title', 'text'],
87+
update: ['title', 'text'],
88+
},
89+
users: {
90+
create: ['email', 'username', 'password'],
91+
},
92+
};
93+
```
94+
7695
---
7796

7897
## Pre-Commit Hook
@@ -95,7 +114,7 @@ or
95114
npm run dev
96115
```
97116

98-
**PS** That can crash it's the first time but don't worry give it 2 sec the scripts gonna work. He just need to created a dist folder :) This way you have only one command to run.
117+
**PS** That can crash if this is the first time but don't worry give it 2 sec the scripts gonna work. He just need to created a dist folder :) This way you have only one command to run.
99118

100119
### DEV-DEBUG
101120

@@ -195,7 +214,7 @@ bash scripts/development.sh
195214
- [Joi](https://github.com/hapijs/joi)
196215
- [Http-Status](https://github.com/adaltas/node-http-status)
197216
- [Lint-Staged](https://github.com/okonet/lint-staged)
198-
- [Pre-Commit](https://github.com/observing/pre-commit)
217+
- [Husky](https://github.com/typicode/husky)
199218
- [Prettier](https://github.com/prettier/prettier)
200219
- [Eslint Config EQuimper](https://github.com/EQuimper/eslint-config-equimper)
201220
- [Eslint Config Prettier](https://github.com/prettier/eslint-config-prettier)
@@ -211,6 +230,7 @@ bash scripts/development.sh
211230
- [NPS](https://github.com/kentcdodds/nps)
212231
- [MongoDB](https://www.mongodb.com/)
213232
- [Mongoose](http://mongoosejs.com/)
233+
- [Webpack2](https://webpack.js.org/)
214234

215235
---
216236

package-scripts.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
},
2323
default: {
2424
description: 'Start project with pm2 on production.',
25-
script: `${crossEnv('NODE_ENV=production')} pm2 start dist/index.bundle.js`,
25+
script: `${crossEnv('NODE_ENV=production')} pm2 start processes.json dist/index.bundle.js`,
2626
},
2727
doc: {
2828
description: 'Documenting the api.',

package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"semantic-release",
3535
"prettier",
3636
"lint-staged",
37-
"webpack"
37+
"webpack2"
3838
],
3939
"license": "MIT",
4040
"lint-staged": {
@@ -78,24 +78,24 @@
7878
"cz-conventional-changelog": "^2.0.0",
7979
"eslint": "^3.19.0",
8080
"eslint-config-equimper": "^1.6.4",
81-
"eslint-config-prettier": "^2.0.0",
81+
"eslint-config-prettier": "^2.1.0",
8282
"faker": "^4.1.0",
8383
"glob": "^7.1.1",
84+
"husky": "^0.13.3",
8485
"istanbul": "1.1.0-alpha.1",
8586
"lint-staged": "^3.4.1",
86-
"mocha": "^3.3.0",
87+
"mocha": "^3.4.1",
8788
"morgan": "^1.8.1",
8889
"nodemon": "^1.11.0",
8990
"nps": "^5.1.0",
9091
"nps-utils": "^1.2.0",
91-
"pre-commit": "^1.2.2",
9292
"prettier": "^1.3.1",
9393
"semantic-release": "^6.3.2",
9494
"shelljs": "^0.7.7",
9595
"superagent": "^3.5.2",
9696
"supertest": "^3.0.0",
9797
"webpack": "fulls1z3/webpack#v2.5.0-harmony",
98-
"webpack-node-externals": "^1.5.4"
98+
"webpack-node-externals": "^1.6.0"
9999
},
100100
"dependencies": {
101101
"bcrypt-nodejs": "^0.0.3",
@@ -109,17 +109,17 @@
109109
"express-winston": "^2.4.0",
110110
"helmet": "^3.6.0",
111111
"http-status": "^1.0.1",
112-
"joi": "^10.4.1",
112+
"joi": "^10.4.2",
113113
"jsonwebtoken": "^7.4.0",
114114
"method-override": "^2.3.8",
115-
"mongoose": "^4.9.8",
115+
"mongoose": "^4.9.9",
116116
"mongoose-unique-validator": "^1.0.5",
117117
"passport": "^0.3.2",
118118
"passport-jwt": "^2.2.1",
119119
"passport-local": "^1.0.0",
120120
"pm2": "^2.4.6",
121121
"pretty-error": "^2.1.0",
122-
"raven": "^1.2.1",
122+
"raven": "^2.0.0",
123123
"slug": "^0.9.1",
124124
"winston": "^2.3.1"
125125
},

processes.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
"script": "./dist",
66
"merge_logs": true,
77
"max_restarts": 20,
8-
"instances": 4,
8+
"instances": "max",
9+
"exec_mode" : "cluster",
910
"max_memory_restart": "200M",
10-
"env": {
11-
"PORT": 3000,
12-
"NODE_ENV": "development"
11+
"env_production" : {
12+
"NODE_ENV": "production"
1313
}
1414
}
1515
]

src/config/constants.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
require('dotenv').config();
22

3+
const WHITELIST = {
4+
posts: {
5+
create: ['title', 'text'],
6+
update: ['title', 'text'],
7+
},
8+
users: {
9+
create: ['email', 'username', 'password'],
10+
},
11+
};
12+
313
const devConfig = {
414
JWT_SECRET: process.env.JWT_SECRET_DEV,
515
MONGO_URL: process.env.MONGO_URL_DEV,
@@ -18,12 +28,7 @@ const prodConfig = {
1828
const defaultConfig = {
1929
PORT: process.env.PORT || 3000,
2030
RAVEN_ID: process.env.RAVEN_ID,
21-
WHITELIST: {
22-
posts: {
23-
create: ['title', 'text'],
24-
update: ['title', 'text'],
25-
},
26-
},
31+
WHITELIST,
2732
};
2833

2934
function envConfig(env) {

src/config/middlewares.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const isTest = process.env.NODE_ENV === 'test';
1818
const isDev = process.env.NODE_ENV === 'development';
1919

2020
export default app => {
21+
app.use(compression());
2122
app.use(bodyParser.json());
2223
app.use(bodyParser.urlencoded({ extended: true }));
2324
app.use(passport.initialize());
@@ -38,5 +39,4 @@ export default app => {
3839
}),
3940
);
4041
}
41-
app.use(compression());
4242
};

src/controllers/user.controller.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import Joi from 'joi';
66
import HTTPStatus from 'http-status';
77

8+
import { filteredBody } from '../utils/filteredBody';
9+
import constants from '../config/constants';
810
import User from '../models/user.model';
911

1012
export const validation = {
@@ -51,8 +53,9 @@ export const validation = {
5153
* }
5254
*/
5355
export async function create(req, res, next) {
56+
const body = filteredBody(req.body, constants.WHITELIST.users.create);
5457
try {
55-
const user = await User.create(req.body);
58+
const user = await User.create(body);
5659
return res.status(HTTPStatus.CREATED).json(user.toAuthJSON());
5760
} catch (e) {
5861
e.status = HTTPStatus.BAD_REQUEST;

src/index.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/**
33
* Server setup
44
*/
5-
65
import express from 'express';
76

87
import './config/database';
@@ -18,17 +17,17 @@ middlewaresConfig(app);
1817
// Add the apiRoutes stack to the server
1918
app.use('/api', ApiRoutes);
2019

21-
// http://www.marcusoft.net/2015/10/eaddrinuse-when-watching-tests-with-mocha-and-supertest.html
20+
// We need this to make sure we don't run a second instance
2221
if (!module.parent) {
2322
app.listen(constants.PORT, err => {
2423
if (err) {
2524
console.error('Cannot run');
2625
} else {
2726
console.log(`
28-
Yep this is working 🍺
29-
App listen on port: ${constants.PORT} 🍕
30-
Env: ${process.env.NODE_ENV} 🦄
31-
`);
27+
Yep this is working 🍺
28+
App listen on port: ${constants.PORT} 🍕
29+
Env: ${process.env.NODE_ENV} 🦄
30+
`);
3231
}
3332
});
3433
}

0 commit comments

Comments
 (0)