-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (25 loc) · 781 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
const path = require('path')
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const logger = require('morgan')
const dotenv = require('dotenv')
dotenv.load()
const app = express()
let port = process.env.PORT || 4242
let env = process.env.NODE_ENV || 'development'
let publicPath = path.join(__dirname, 'public')
if (env === 'development') {
const webpackBundler = require('./lib/middleware/webpack-bundler-middleware')
app.use(webpackBundler())
app.use(logger('dev'))
}
app.use(bodyParser.json())
app.use(cors())
app.use(express.static(publicPath))
app.get('*', (req, res) => {
return res.sendFile(path.join(publicPath, 'index.html'))
})
app.listen(port, () => {
console.log(`NODE_ENV ${env} on ${port}`)
})