forked from dlyt/YCool_Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (36 loc) · 1.1 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
import Koa from 'koa'
import bodyParser from 'koa-bodyparser'
import convert from 'koa-convert'
import logger from 'koa-logger'
import mongoose from 'mongoose'
import session from 'koa-generic-session'
import passport from 'koa-passport'
import mount from 'koa-mount'
import serve from 'koa-static'
import config from '../config'
import handle from '../src/utils/handle'
import { errorMiddleware } from '../src/middleware'
global.Handle = handle
const app = new Koa()
app.keys = [config.session]
mongoose.Promise = global.Promise
mongoose.connect(config.database)
app.use(convert(logger()))
app.use(bodyParser())
app.use(convert(session()))
app.use(errorMiddleware())
app.use(convert(mount('/docs', serve(`${process.cwd()}/docs`))))
require('../config/passport')
app.use(passport.initialize())
app.use(passport.session())
const modules = require('../src/modules')
modules(app)
app.listen(config.port, () => {
console.log(`Server started on ${config.port}`)
})
//更新小说爬虫
const UpdateNovel = require('../src/utils/updateNovel')
if (app.env === 'production') {
UpdateNovel.start()
}
export default app