-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
54 lines (47 loc) · 1.63 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var webpack = require('webpack')
var express = require('express')
var ReactDOMServer = require('react-dom/server')
var WebpackDevServer = require('webpack-dev-server')
var config = require('./webpack.config')
var path = require('path')
const server = new WebpackDevServer(
webpack(config), {
publicPath: config.output.publicPath,
contentBase: 'app',
historyApiFallback: {
index: '/'
}
}
)
server.use('/', function(req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
});
server.listen(8080, 'localhost', (error, result) => {
if (error) { console.log(error) }
console.log('Listening at localhost:8080')
})
// Server-side react sendering with redux: https://medium.com/@firasd/quick-start-tutorial-universal-react-with-server-side-rendering-76fe5363d6e#.mmtc61rw9
// http://jmfurlott.com/tutorial-setting-up-a-simple-isomorphic-react-app/
// var app = express()
// app.get(['/'], function(req, res) {
// /* Use React Router */
// var ReactRouter = require('react-router');
// var match = ReactRouter.match;
// var routes = require('./app/routes.js').routes
// match({routes: routes, location: req.url}, function(error, redirectLocation, renderProps) {
// if (error) {
// res.status(500).send(error.message)
// } else if (redirectLocation) {
// res.redirect(302, redirectLocation.pathname + redirectLocation.search)
// } else if (renderProps) {
// res.send("<!DOCTYPE html>"+
// ReactDOMServer.renderToString(
// RouterContext(renderProps)
// )
// )
// } else {
// res.status(404).send('Not found')
// }
// })
// })
// app.listen(8080)