-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (38 loc) · 1.12 KB
/
app.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
const Koa = require("koa");
// const bodyparser = require("koa-bodyparser");
const koaBody = require("koa-body");
const InitManager = require("./core/init");
const catchError = require("./middlewares/exceptions");
const cors = require("koa-cors");
const helmet = require("koa-helmet");
const koaStatic = require("koa-static");
const path = require("path");
const app = new Koa();
// 注册helmet中间件防止xss攻击
app.use(helmet());
// 允许跨域
app.use(
cors({
origin: "*",
})
);
// 处理静态资源
app.use(koaStatic(path.join(__dirname, "./uploads/article")));
app.use(koaStatic(path.join(__dirname, "./uploads/avatar")));
app.use(koaStatic(path.join(__dirname, "./uploads/circle")));
app.use(koaStatic(path.join(__dirname, "./uploads/news")));
app.use(koaStatic(path.join(__dirname, "./uploads/content")));
app.use(koaStatic(path.join(__dirname, "./static/apk")));
// 注册全局异常处理中间件:
app.use(catchError);
// app.use(bodyparser());
app.use(
koaBody({
multipart: true,
})
);
// 初始化管理器:
InitManager.initCore(app);
app.listen(3001, () => {
console.log("程序已启动...");
});