-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
34 lines (28 loc) · 1.03 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const Koa = require('koa');
const path = require('path');
const {aureliaKoaMiddleware} = require('aurelia-middleware-koa');
const initialState = require('./src/store/prepopulated-state');
var port = process.env.PORT || 8080;
const app = new Koa();
const bundle = './dist/server.bundle';
const template = require('fs').readFileSync(path.resolve('./dist/index.ssr.html'), 'utf-8')
.replace("// [prerendered model]", `window.__PRELOADED_STATE__ = ${JSON.stringify(initialState)};`);
app.use(aureliaKoaMiddleware({
preboot: true,
bundlePath: require.resolve(bundle),
template
}, {
main: () => {
delete require.cache[require.resolve(bundle)];
return require(bundle);
}
}));
app.use(require('koa-static')(path.resolve(__dirname)));
app.use(require('koa-static')(path.resolve(__dirname, 'dist')));
console.log('Starting server....');
app.listen(port);
console.log(`Listening at http://localhost:${port}/`);
process.on('unhandledRejection', error => {
console.log('unhandledRejection', error.message);
console.log(error.stack);
});