-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
46 lines (34 loc) · 903 Bytes
/
index.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
import Koa from 'koa'
import koaRouter from 'koa-router'
import json from 'koa-json'
import logger from 'koa-logger'
import api from './server/routes/api.js'
import cors from '@koa/cors'
import koaBody from 'koa-body'
import statics from 'koa-static'
import path from 'path'
const app = new Koa()
const router = koaRouter()
app.use(cors());
app.use(koaBody({
multipart: true,
formidable: {
maxFileSize: 500*1024*1024 // 设置上传文件大小最大限制,默认2M
}
}))
app.use(json())
app.use(logger())
// 静态服务
app.use(statics(path.join(__dirname, './upload/')))
app.use(async (ctx,next) => {
await next()
})
router.use('/api', api.routes())
app.use(router.routes())
app.on('error',(err,ctx) => {
console.log('server error', err)
})
app.listen(3000,()=>{
console.log('服务启动成功,端口:3000,地址:http://localhost:3000')
})
export default app