-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (24 loc) · 821 Bytes
/
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
import express from 'express';
import mustacheExpress from 'mustache-express';
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import { StaticRouter } from 'react-router';
import App from './src/App';
const { PORT = 8000 } = process.env;
const app = express();
app.engine('html', mustacheExpress());
app.set('views', './build');
app.set('view engine', 'mustache');
app.use('/static', express.static('build/static'));
app.get('/favicon.png', (req, res) => {
res.sendFile(`${__dirname}/build/favicon.png`);
});
app.get('/*', (req, res) => {
const html = ReactDOMServer.renderToString(
<StaticRouter location={req.url}>
<App />
</StaticRouter>
);
res.render('index.html', { content: html });
});
app.listen(PORT, () => console.log(`Server listening on port ${PORT}`));