refactor(app.js): Extract urlencodedParser to utils module

This commit is contained in:
BoHong Li 2017-04-12 05:31:22 +08:00 committed by Raccoon Li
parent dee77c459a
commit 9f1f16c8e3
2 changed files with 10 additions and 6 deletions

7
app.js
View file

@ -7,6 +7,7 @@ var passport = require('passport')
var methodOverride = require('method-override') var methodOverride = require('method-override')
var cookieParser = require('cookie-parser') var cookieParser = require('cookie-parser')
var bodyParser = require('body-parser') var bodyParser = require('body-parser')
const {urlencodedParser} = require('./lib/web/utils')
var compression = require('compression') var compression = require('compression')
var session = require('express-session') var session = require('express-session')
var SequelizeStore = require('connect-session-sequelize')(session.Store) var SequelizeStore = require('connect-session-sequelize')(session.Store)
@ -98,12 +99,6 @@ realtime.io = io
// methodOverride // methodOverride
app.use(methodOverride('_method')) app.use(methodOverride('_method'))
// create application/x-www-form-urlencoded parser
var urlencodedParser = bodyParser.urlencoded({
extended: false,
limit: 1024 * 1024 * 10 // 10 mb
})
// session store // session store
var sessionStore = new SequelizeStore({ var sessionStore = new SequelizeStore({
db: models.sequelize db: models.sequelize

9
lib/web/utils.js Normal file
View file

@ -0,0 +1,9 @@
'use strict'
const bodyParser = require('body-parser')
// create application/x-www-form-urlencoded parser
exports.urlencodedParser = bodyParser.urlencoded({
extended: false,
limit: 1024 * 1024 * 10 // 10 mb
})