Update function name

This commit is contained in:
MICHAEL JACKSON 2017-10-20 08:01:10 -04:00
parent b92f803b97
commit 6e51275494
1 changed files with 23 additions and 14 deletions

View File

@ -9,7 +9,7 @@ const packageURL = require('./middleware/packageURL')
const fetchFile = require('./middleware/fetchFile')
const serveFile = require('./middleware/serveFile')
morgan.token('fwd', function (req) {
morgan.token('fwd', function(req) {
return req.get('x-forwarded-for').replace(/\s/g, '')
})
@ -20,30 +20,38 @@ const PackageBlacklist = require('./PackageBlacklist').blacklist
function errorHandler(err, req, res, next) {
console.error(err.stack)
res.status(500).type('text').send('Internal Server Error')
res
.status(500)
.type('text')
.send('Internal Server Error')
next(err)
}
function createApp() {
function createServer() {
const app = express()
app.disable('x-powered-by')
if (process.env.NODE_ENV !== 'test') {
app.use(morgan(process.env.NODE_ENV === 'production'
// Modified version of the Heroku router's log format
// https://devcenter.heroku.com/articles/http-routing#heroku-router-log-format
? 'method=:method path=":url" host=:req[host] request_id=:req[x-request-id] cf_ray=:req[cf-ray] fwd=:fwd status=:status bytes=:res[content-length]'
: 'dev'
))
app.use(
morgan(
process.env.NODE_ENV === 'production'
? // Modified version of the Heroku router's log format
// https://devcenter.heroku.com/articles/http-routing#heroku-router-log-format
'method=:method path=":url" host=:req[host] request_id=:req[x-request-id] cf_ray=:req[cf-ray] fwd=:fwd status=:status bytes=:res[content-length]'
: 'dev'
)
)
}
app.use(errorHandler)
app.use(cors())
app.use(express.static('build', {
maxAge: '365d'
}))
app.use(
express.static('build', {
maxAge: '365d'
})
)
if (process.env.NODE_ENV !== 'test') {
const createSearchServer = require('./createSearchServer')
@ -53,7 +61,8 @@ function createApp() {
app.use('/_stats', createStatsServer())
}
app.use('/',
app.use(
'/',
packageURL,
checkBlacklist(PackageBlacklist),
fetchFile,
@ -63,4 +72,4 @@ function createApp() {
return app
}
module.exports = createApp
module.exports = createServer