Skip to content

Commit 4271999

Browse files
authored
feat(Security): Secure app using helmet (#21)
Closes #13
1 parent 6dfb765 commit 4271999

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Heavily inspired from [Egghead.io - How to Write an Open Source JavaScript Libra
2929
| Debugging via [debug](https://www.npmjs.com/package/debug) | Instead of inserting and deleting console.log you can replace it with the debug function and just leave it there. You can then selectively debug portions of your code by setting DEBUG env variable. If DEBUG env variable is not set, nothing is displayed to the console. |
3030
| Promisified Code via [bluebird](https://github.com/petkaantonov/bluebird) | We love promise, don't we ? All our code is promisified and even so our tests via [supertest-as-promised](https://www.npmjs.com/package/supertest-as-promised). |
3131
| API parameter validation via [express-validation](https://www.npmjs.com/package/express-validation) | Validate body, params, query, headers and cookies of a request (via middleware) and return a response with errors; if any of the configured validation rules fail. You won't anymore need to make your route handler dirty with such validations. |
32+
| Secure app via [helmet](https://github.com/helmetjs/helmet) | Helmet helps secure Express apps by setting various HTTP headers. |
3233

3334
- CORS support via [cors](https://github.com/troygoode/node-cors)
3435
- Uses [http-status](https://www.npmjs.com/package/http-status) to set http status code. It is recommended to use `httpStatus.INTERNAL_SERVER_ERROR` instead of directly using `500` when setting status code.

config/express.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import cors from 'cors';
88
import httpStatus from 'http-status';
99
import expressWinston from 'express-winston';
1010
import expressValidation from 'express-validation';
11+
import helmet from 'helmet';
1112
import winstonInstance from './winston';
1213
import routes from '../server/routes';
1314
import config from './env';
@@ -27,8 +28,8 @@ app.use(cookieParser());
2728
app.use(compress());
2829
app.use(methodOverride());
2930

30-
// disable 'X-Powered-By' header in response
31-
app.disable('x-powered-by');
31+
// secure apps by setting various HTTP headers
32+
app.use(helmet());
3233

3334
// enable CORS - Cross Origin Resource Sharing
3435
app.use(cors());

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"express": "4.14.0",
4545
"express-validation": "1.0.0",
4646
"express-winston": "^1.2.0",
47+
"helmet": "2.1.1",
4748
"http-status": "^0.2.0",
4849
"joi": "8.4.2",
4950
"lodash": "^4.0.1",

0 commit comments

Comments
 (0)