-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
36 lines (31 loc) · 1.01 KB
/
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
const Koa = require('koa');
const path = require('path');
const static = require('koa-static');
const proxy = require('koa2-proxy-middleware');
const compress = require('koa-compress');
const app = new Koa();
const port = process.env.port || 3333;
const staticPath = './dist';
const hostUrl = process.env.hostUrl || 'http://transfer.lian-med.com:9988';
const formDescriptionUrl = process.env.formDescriptionUrl || 'http://127.0.0.1:3335';
app.use(compress({ threshold: 1024 }));
app.use(static(path.join(__dirname, staticPath)));
const options = {
targets: {
'/api/form-descriptions(.*)': {
target: formDescriptionUrl,
changeOrigin: true,
// pathRewrite: { '^/server': '' },
},
// (.*) means anything
'/api/(.*)': {
target: hostUrl,
changeOrigin: true,
},
},
};
app.use(proxy(options));
app.listen(port, () => {
console.log(`apiHostUrl: http://localhost:${hostUrl}, formDescriptionUrl: ${formDescriptionUrl}`);
console.log(`server link is: http://localhost:${port}`);
});