1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-11 05:40:11 +02:00

Use hapi instead of express

This commit is contained in:
geek 2016-12-30 15:46:55 -06:00
parent 609499bc61
commit f8a0fba192

View File

@ -19,11 +19,18 @@ const server = new hapi.Server({
}
}
});
server.connection({ port: process.env.PORT || 8000 });
server.connection({
port: process.env.PORT || 8000
});
server.register([
inert,
{ register: understood, options: { default: 'en-us', localesDir: path.join(__dirname, '../static/locales') } }],
{
register: understood,
options: {
default: 'en-us', localesDir: path.join(__dirname, '../static/locales')
}
}],
(err) => {
if (err) {
console.error(err);
@ -42,7 +49,9 @@ server.register([
}
});
server.route({ method: '*', path: '/{param*}', handler: defaultHandler });
server.route({
method: '*', path: '/{param*}', handler: defaultHandler
});
server.start((err) => {
if (err) {
@ -52,9 +61,11 @@ server.register([
console.log(`Server running at: http://localhost:${server.info.port}`);
});
});
});
function defaultHandler (request, reply) {
function defaultHandler(request, reply) {
const locales = (request.locale || '').toLowerCase().split(/\-/);
reply(html({ locale: locales[1], lang: locales[0] }));
reply(html({
locale: locales[1], lang: locales[0]
}));
}