forked from lastIndexOf/E-commerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·47 lines (39 loc) · 1.06 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
const
Koa = require('koa'),
session = require('koa-session'),
renderer = require('koa-views'),
bodyParser = require('koa-bodyparser'),
Router = require('koa-router'),
static = require('koa-static2'),
logger = require('koa-logger'),
mongoose = require('mongoose')
mongoose.Promise = Promise
const config = require('./config.js')
const app = new Koa()
const router = new Router()
const render = renderer('./app/view', {
map: { html: 'pug' },
extension: 'pug'
})
if (config.env === 'development') {
mongoose.set('debug', true)
}
mongoose.connect(config.db.url, err => {
if (err)
console.error(err)
else
console.log('connect to mongoDB success!')
})
require('./router/router.js')(router)
app.keys = config.keys
app
.use(logger())
.use(static('/static', './dist'))
.use(render)
.use(session(config.session, app))
.use(bodyParser({ formLimit: '50mb' }))
.use(router.routes())
.use(router.allowedMethods())
app.listen(config.serverConfig.port, () => {
console.log(`server running at http://localhost:${ config.port }`)
})