1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-28 22:20:06 +02:00
copilot/frontend/server/index.js

45 lines
904 B
JavaScript
Raw Normal View History

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