format server style

This commit is contained in:
Sérgio Ramos 2017-01-03 13:36:09 +00:00
parent 44ac7956e2
commit 96df29f85b

View File

@ -19,53 +19,61 @@ const server = new hapi.Server({
} }
} }
}); });
server.connection({ server.connection({
port: process.env.PORT || 8000 port: process.env.PORT || 8000
}); });
server.register([ const plugins = [
inert, inert,
{ {
register: understood, register: understood,
options: { 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) { if (err) {
console.error(err); console.error(err);
process.exit(1); process.exit(1);
} }
server.route({ console.log(`Server running at: http://localhost:${server.info.port}`);
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}`);
});
}); });
});
function defaultHandler(request, reply) {
const locales = (request.locale || '').toLowerCase().split(/\-/);
reply(html({
locale: locales[1], lang: locales[0]
}));
}