koa-proxies
koa-proxies copied to clipboard
should middleware obtain the results of proxy?
const Koa = require("koa");
const http = require("http");
const proxy = require("koa-proxies");
const router = require("koa-router")();
const app = new Koa();
app.use(async (ctx, next) => {
console.log("start");
await next();
console.log("end", ctx.body);
});
app.use(
proxy("/proxy", (params, ctx) => {
ctx.respond = false;
return {
target: "http://127.0.0.1:22311",
changeOrigin: true,
};
})
);
router.get("/test", async function (ctx, next) {
ctx.body = "test";
next();
});
app.use(router.routes(), router.allowedMethods());
var server = http.createServer(app.callback());
const hostname = "0.0.0.0";
const port = 8081;
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
When I access /test
, I can get the following results:
However, when I access /proxy
, I cannot get the proxy results from end.
I know that the return result is handled through
proxyRes
, but what causes this difference?