Skip to content

Commit ec069bb

Browse files
committed
Add cookie parser
1 parent 8cf0d7d commit ec069bb

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

config/express.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
import express from 'express';
22
import logger from 'morgan';
33
import bodyParser from 'body-parser';
4+
import cookieParser from 'cookie-parser';
45
import compress from 'compression';
56
import methodOverride from 'method-override';
67
import cors from 'cors';
78
import httpStatus from 'http-status';
89
import routes from '../server/routes';
10+
import config from './env';
911
import * as utilityService from '../server/services/utility';
1012

1113
const app = express();
1214

1315
app.use(logger('dev'));
1416

15-
// parses body params and attaches them to req.body
17+
// parse body params and attache them to req.body
1618
app.use(bodyParser.json());
1719
app.use(bodyParser.urlencoded({ extended: true }));
1820

21+
app.use(cookieParser());
1922
app.use(compress());
2023
app.use(methodOverride());
2124

22-
// Enable CORS - Cross Origin Resource Sharing
25+
// enable CORS - Cross Origin Resource Sharing
2326
app.use(cors());
2427

2528
// mount all routes on /api path
@@ -37,11 +40,11 @@ app.use((req, res, next) => {
3740
return next(err);
3841
});
3942

40-
// error handler
43+
// error handler, send stacktrace only during development
4144
app.use((err, req, res, next) => // eslint-disable-line no-unused-vars
4245
res.status(err.status).json({
4346
message: err.isPublic ? err.message : httpStatus[err.status],
44-
error: process.env.NODE_ENV === 'development' ? err : {}
47+
error: config.NODE_ENV === 'development' ? err : {}
4548
})
4649
);
4750

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
{
22
"name": "express-es6-rest-api-starter",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Starter project for an ES6 RESTful Express API",
55
"main": "index.js",
66
"private": false,
7+
"engines": {
8+
"node": "4.2.x",
9+
"npm": "3.3.x"
10+
},
711
"scripts": {
812
"start": "gulp serve",
913
"test": "echo \"Error: no test specified\" && exit 1"
@@ -16,6 +20,7 @@
1620
"dependencies": {
1721
"body-parser": "~1.13.2",
1822
"compression": "^1.6.1",
23+
"cookie-parser": "^1.4.1",
1924
"cors": "^2.7.1",
2025
"debug": "^2.2.0",
2126
"dotenv": "^2.0.0",

0 commit comments

Comments
 (0)