generated from KBVE/nodepy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
53 lines (51 loc) · 1.29 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
45
46
47
48
49
50
51
52
53
//? [Main App]
//TODO [Migrate to Typescript]
//* [IMPORT]
const Koa = require("koa");
const proxy = require("koa-proxies");
const path = require("path");
const parser = require("koa-bodyparser");
const httpsProxyAgent = require("https-proxy-agent");
const router = require("./router");
const serve = require("koa-static");
const _v = require("./v");
const App = new Koa();
const port = 5000;
const staticDirPath = path.join(__dirname, "public");
App
.use(
proxy("/api", {
target: "https://pb.kbve.com/",
changeOrigin: true,
//secure: false,
timeout: 300000,
//rewrite: path => path.replace(/^\/kbvedatabase(\/|\/\w+)?$/, '/_'),
logs: true,
})
)
.use(
proxy("/_", {
target: "https://pb.kbve.com/",
changeOrigin: true,
//secure: false,
timeout: 300000,
//rewrite: path => path.replace(/^\/kbvedatabase(\/|\/\w+)?$/, '/_'),
logs: true,
})
)
.use(parser())
.use(router.routes())
.use(async (ctx, next) => {
try {
await next();
} catch (err) {
ctx.status = err.statusCode || err.status || 500;
ctx.body = {
message: err.message,
};
}
})
.use(serve(staticDirPath))
.listen(port, () => {
_v(`Launching at http://127.0.0.1:${port}/ 🚀`);
});