-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
55 lines (45 loc) · 1.43 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
53
54
55
const express = require('express')
const bodyParser = require('body-parser')
const mongoose = require('mongoose')
const path = require('path')
const conf = require('./conf')
const routes = require('./routes')
const app = express()
const cors = require('cors')
const Meta = require('./utils/Meta')
const open = require('open')
app.use(cors())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
const webpack = require('webpack')
const webpackConfig = require('./webpack.config')
const compiler = webpack(webpackConfig)
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: webpackConfig.output.publicPath
}))
app.use(require('webpack-hot-middleware')(compiler))
//mogoose default Promise is deprecated
mongoose.Promise = global.Promise
mongoose.connect(conf.databaseUrl)
.connection.on('error', () => {
throw new Error('unable to connect to database ' + conf.databaseUrl)
})
.on('connected', () => {
console.log('connected to database ' + conf.databaseUrl)
})
// if (Meta.isLocalDev) {
// app.use('/public/', express.static(path.join(__dirname, 'src/dist')))
// }
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'src/index.html'))
})
app.use('/api', (req, res, next)=>{
return next()
},routes)
app.listen(process.env.PORT || 9090, (err) => {
if (!err) {
console.log('server runing on port ' + process.env.PORT)
open('http://127.0.0.1:9090/')
}
})