-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.jsx
117 lines (99 loc) · 3.61 KB
/
app.jsx
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import express from 'express';
import { createServer } from 'http';
import path from 'path';
import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import React from 'react';
import { renderToString } from 'react-dom/server';
import createLocation from 'history/lib/createLocation';
import { RouterContext, match } from 'react-router';
import routes from './routes/routes';
const config = require('./webpack.config');
const compiler = webpack(config);
const app = express();
app.use((req, res, next) => {
const location = createLocation(req.originalUrl);
const css = new Set();
match({ routes, location }, (error, redirectLocation, renderProps) => {
if (redirectLocation) return res.redirect(redirectLocation.pathname);
if (error) return next(error.message);
if (renderProps == null) return next(error);
const markup = renderToString(<RouterContext {...renderProps} />);
const html = [
`<!DOCTYPE html>
<html>
<head>
<title>EPAM - Advanced Data Visualization With D3.js</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="stylesheet" href="http://facebook.github.io/react/css/syntax.css">
<link rel="stylesheet" href="http://facebook.github.io/react/css/codemirror.css">
<link rel="stylesheet" href="http://facebook.github.io/react/css/react.css">
<style type="text/css">${[...css].join('')}</style>
<style>
html, body, #root { height: 100%; } a { text-decoration: none !important; }
.a-canvas { width: 100% !important;height: 100% }
.playgroundCode {
width: initial;
max-width: initial;
display: flex;
flex: 1;
}
.playground {
display: flex;
flex: 1;
}
.playgroundPreview {
display: flex;
flex: 1;
width: initial;
}
.playgroundPreview div {
display: flex;
flex: 1;
}
.playgroundStage {
flex: 1;
}
.CodeMirror {
height: 75vh;
}
p.big.imeanit.really {
font-size: 40px;
}
p[not-so=big].big.imeanit.really {
font-size: 32px;
}
.slidesContainer > div {
flex: 1;
display: flex;
}
.slidesContainer > div > div {
flex: 1;
}
</style>
</head>
<body class="loading">
<div id="root"><div>${markup}</div></div>
<script type="text/javascript" src="/aframe.js" charset="utf-8"></script>
<script type="text/javascript" src="/babel.js" charset="utf-8"></script>
<script type="text/javascript" src="/polyfill.js" charset="utf-8"></script>
<script type="text/javascript" src="/app.bundle.js" charset="utf-8"></script>
</body>
</html>`,
].join('');
res.setHeader('Content-Type', 'text/html');
return res.send(html);
});
});
app.use(webpackDevMiddleware(compiler, {
stats: {
colors: true,
},
}));
app.use(webpackHotMiddleware(compiler));
app.use(express.static(path.join(__dirname, 'public')));
const server = createServer(app);
server.listen(8081);