forked from ovasylenko/week-2-react-routes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·52 lines (41 loc) · 1.04 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
/* eslint-disable import/no-duplicates */
import express from 'express'
import path from 'path'
import cors from 'cors'
import bodyParser from 'body-parser'
import cookieParser from 'cookie-parser'
import Html from '../client/html'
const port = process.env.PORT || 3000
const server = express()
server.use(cors())
server.use(express.static(path.resolve(__dirname, '../dist/assets')))
server.use(bodyParser.urlencoded({ limit: '50mb', extended: true, parameterLimit: 50000 }))
server.use(bodyParser.json({ limit: '50mb', extended: true }))
server.use(cookieParser())
server.use('/api/', (req, res) => {
res.status(404)
res.end()
})
server.get('/', (req, res) => {
// const body = renderToString(<Root />);
const title = 'Server side Rendering'
res.send(
Html({
body: '',
title
})
)
})
server.get('/*', (req, res) => {
const initialState = {
location: req.url
}
return res.send(
Html({
body: '',
initialState
})
)
})
server.listen(port)
console.log(`Serving at http://localhost:${port}`)