-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-server.js
63 lines (51 loc) · 1.65 KB
/
init-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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import http from 'http';
import express from 'express';
import { create } from 'laxar';
import artifacts from 'laxar-loader/artifacts?flow=main&theme=default';
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
require('es6-promise').polyfill();
const config = {
name: 'simple-laxar-app',
router: {
query: {
enabled: true
},
navigo: {
useHash: true
}
},
logging: {
threshold: 'TRACE'
},
theme: 'default'
};
const dom = new JSDOM('<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>simple-laxar-app</title>' +
'<link href="init-client.bundle.css" rel="stylesheet" type="text/css"></head><body>' +
'<div><p>Info: This is the SSR Version of LaxarJS Application</p></div>' +
'<div data-ax-page></div></body></html>');
global.document = dom.window.document;
global.window = dom.window;
const element = document.querySelector( '[data-ax-page]' );
create( [], artifacts, config )
//.flow( 'main', element )
.page( 'home', element )
.bootstrap()
.then( () => {
const content = dom.window.document.documentElement.outerHTML;
const app = express();
app.get('/', (req, res) => {
res.send(content)
});
app.use(express.static('build')); //Provide directory with CSS file
const server = http.createServer(app);
let currentApp = app;
server.listen(3000);
if (module.hot) {
module.hot.accept('./server', () => {
server.removeListener('request', currentApp);
server.on('request', app);
currentApp = app
})
}
} );