-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
32 lines (25 loc) · 831 Bytes
/
index.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
const path = require('path')
const express = require('express')
const hbs = require('express-hbs')
const Bundler = require('parcel-bundler')
const render = require('./server/src/entry-server').default
const app = express()
// use Parcel bundler hot module reloading when in development environment
if (process.env.NODE_ENV === 'development') {
const bundler = new Bundler('src/entry-client.js', {
outFile: 'main.js',
outDir: 'dist',
})
app.use(bundler.middleware())
}
app.use(express.static(path.join(__dirname, 'dist')))
// view engine setup
app.engine('hbs', hbs.express4())
app.set('view engine', 'hbs')
app.set('views', path.join(__dirname, 'views'))
app.all('*', (req, res) => {
render(req).then(({html, state}) => {
res.render('base', {html, state: JSON.stringify(state)})
})
})
app.listen(3000)