forked from zoeydawn/earth-sandwich
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (30 loc) · 1.01 KB
/
app.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 PORT = process.env.PORT || 8000
require('dotenv').config();
const path = require('path')
const morgan = require('morgan')
const express = require('express')
const webpack = require('webpack')
const bodyParser = require('body-parser')
const webpackConfig = require('./webpack.config')
const webpackDevMiddleware = require('webpack-dev-middleware')
const webpackHotMiddleware = require('webpack-hot-middleware')
const app = express()
const compiler = webpack(webpackConfig)
app.use(morgan('dev'))
app.use(express.static('build'))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(webpackDevMiddleware(compiler, {
publicPath: webpackConfig.output.publicPath, noInfo: true
}))
app.use(webpackHotMiddleware(compiler))
// if(!app.working) {
// make.app(work)
// }
app.use('/api',require('./routes/api'))
app.use("*", function(req, res) {
res.sendFile(path.join(__dirname, './build/index.html'));
});
app.listen(PORT, err => {
console.log(err || `Express listening on port ${PORT}`);
})