1
0
mirror of https://github.com/yldio/copilot.git synced 2024-12-01 07:30:07 +02:00
copilot/frontend/server/index.js
2016-10-24 16:31:05 +01:00

45 lines
904 B
JavaScript

const template = require('lodash.template');
const locale = require('locale');
const path = require('path');
const express = require('express');
const st = require('st');
const fs = require('fs');
const app = express();
const index = path.join(__dirname, './index.html');
const html = template(fs.readFileSync(index, 'utf-8'));
var mount = st({
path: path.join(__dirname, '../static'),
url: 'static/',
index: false,
dot: false,
passthrough: false,
gzip: true,
cors: false
});
app.use(mount);
app.use(locale(require('./locales')));
app.get('/*', (req, res, next) => {
const locale = (req.locale || '').toLowerCase();
const lang = locale.split(/\-/)[0];
res.header('Content-Type', 'text/html');
res.send(html({
locale,
lang
}));
});
app.listen(8000, (err, address) => {
if (err) {
throw err;
}
console.log('Server running at: http://localhost:8000');
});