-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (32 loc) · 919 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
32
33
34
35
36
37
38
39
const path = require('path')
const express = require('express')
const cookieParser = require('cookie-parser')
const app = express()
app.use('/dist', express.static(path.join(__dirname, 'dist')))
app.use(cookieParser())
const __DEV__ = process.env.NODE_ENV !== 'production'
app.get('*', (req, res) => {
const dir = req.cookies.dir === 'rtl' ? 'rtl' : 'ltr'
// the two lines below are only used for production
// depending on the value of the `dir` cookie, we use
// app.css or app.rtl.css
const cssUrl = `/dist/app${dir === 'rtl' ? '.rtl' : ''}.css`
const css = __DEV__ ? '' : `<link rel="stylesheet" href="${cssUrl}">`
const html = `
<!DOCTYPE html>
<html dir=${dir}>
<head>
<title></title>
${css}
</head>
<body>
<div id="root"></div>
<script src="/dist/app.js"></script>
</body>
</html>
`
res.send(html)
})
app.listen(3000, () => {
console.log(`Listening on http://localhost:3000`)
})