永远不会解决代理的POST请求

时间:2018-07-29 13:04:00

标签: node.js proxy koa

我在我的PI上运行了几个REST API,而不是为每个应用程序分配唯一的端口,并向所有人开放,我宁愿拥有1个对公众可见的应用程序,然后代理所有请求从该主应用程序到其他API。

为此,我正在使用koa-proxies

import * as mount from 'koa-mount';
import *  as proxy from 'koa-proxies';

app
    .use(bodyParser())
    .use(mount('/wizard-cube', proxy('/', {
        target: 'http://localhost:3596',
        logs: true
    })));
const sslOptions = {
    key: fs.readFileSync(...),
    cert: fs.readFileSync(...)
};
http.createServer(app.callback()).listen(3000);
https.createServer(sslOptions, app.callback()).listen(3001);

在3596上提供的另一个API看起来像这样:

router.get('/', (ctx: Koa.Context, next: Function) => {
    ctx.response.body = {message: 'GET request!',};
    return next();
});
router.post('/', (ctx: Koa.Context, next: Function) => {
    ctx.response.body = {message: 'POST request!',};
    return next();
});
app
    .use(bodyParser())
    .use(router.routes())
    .use(router.allowedMethods())
    .listen(3596);

如果我将GET请求发送到http://localhost:3000/wizard-cube,则会收到响应,但是如果我将POST请求发送到相同的URL,则连接永远不会终止,也不会收到响应。我在做什么错了?

0 个答案:

没有答案