forked from hasura/graphql-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
60 lines (52 loc) · 1.41 KB
/
server.js
File metadata and controls
60 lines (52 loc) · 1.41 KB
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
import Express from 'express';
import React from 'react';
import ReactDOM from 'react-dom/server';
import config from './config';
// import favicon from 'serve-favicon';
import path from 'path';
import Html from './helpers/Html';
import http from 'http';
global.__DISABLE_SSR__ = true;
// Express middleware
const app = new Express();
const server = new http.Server(app);
/* Constants */
/* Routes and middleware */
// app.use(favicon(path.join(__dirname, '..', 'static', 'favicon_green.png')));
app.use('/rstatic', Express.static(path.join(__dirname, '..', 'static')));
app.use((req, res) => {
if (__DEVELOPMENT__) {
// Do not cache webpack stats: the script file would change since
// hot module replacement is enabled in the development env
webpackIsomorphicTools.refresh();
}
// Initialize the store here
function hydrateOnClient() {
res.send(
'<!doctype html>\n' +
ReactDOM.renderToString(
<Html assets={webpackIsomorphicTools.assets()} />
)
);
}
if (__DISABLE_SSR__) {
hydrateOnClient();
return;
}
});
if (config.port) {
server.listen(config.port, config.host, err => {
if (err) {
console.error(err);
}
console.info(
'==> 💻 Open http://%s:%s in a browser to view the app.',
config.host,
config.port
);
});
} else {
console.error(
'==> ERROR: No PORT environment variable has been specified'
);
}