From 96df29f85b0aedcb798aeb7d9824bf1f2307c08d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Tue, 3 Jan 2017 13:36:09 +0000 Subject: [PATCH] format server style --- frontend/server/index.js | 78 ++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/frontend/server/index.js b/frontend/server/index.js index e1aa69b9..f7a70255 100644 --- a/frontend/server/index.js +++ b/frontend/server/index.js @@ -19,53 +19,61 @@ const server = new hapi.Server({ } } }); + server.connection({ port: process.env.PORT || 8000 }); -server.register([ +const plugins = [ inert, { register: understood, options: { - default: 'en-us', localesDir: path.join(__dirname, '../static/locales') + 'default': 'en-us', + localesDir: path.join(__dirname, '../static/locales') } - }], - (err) => { + } +]; + +const defaultHandler = (request, reply) => { + const locales = (request.locale || '').toLowerCase().split(/\-/); + + reply(html({ + locale: locales[1], + lang: locales[0] + })); +}; + +server.register(plugins, (err) => { + if (err) { + console.error(err); + process.exit(1); + } + + server.route({ + method: 'GET', + path: '/static/{param*}', + handler: { + directory: { + path: '.', + redirectToSlash: true, + index: false + } + } + }); + + server.route({ + method: '*', + path: '/{param*}', + handler: defaultHandler + }); + + server.start((err) => { if (err) { console.error(err); process.exit(1); } - server.route({ - method: 'GET', - path: '/static/{param*}', - handler: { - directory: { - path: '.', - redirectToSlash: true, - index: false - } - } - }); - - server.route({ - method: '*', path: '/{param*}', handler: defaultHandler - }); - - server.start((err) => { - if (err) { - console.error(err); - process.exit(1); - } - - console.log(`Server running at: http://localhost:${server.info.port}`); - }); + console.log(`Server running at: http://localhost:${server.info.port}`); }); - -function defaultHandler(request, reply) { - const locales = (request.locale || '').toLowerCase().split(/\-/); - reply(html({ - locale: locales[1], lang: locales[0] - })); -} +});