From 6e51275494f1486374816930ac6c744935187e7d Mon Sep 17 00:00:00 2001 From: MICHAEL JACKSON Date: Fri, 20 Oct 2017 08:01:10 -0400 Subject: [PATCH] Update function name --- server/createServer.js | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/server/createServer.js b/server/createServer.js index 2ddc2d6..e52e877 100644 --- a/server/createServer.js +++ b/server/createServer.js @@ -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