koa-proxies icon indicating copy to clipboard operation
koa-proxies copied to clipboard

should middleware obtain the results of proxy?

Open kajweb opened this issue 7 months ago • 0 comments

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: image

However, when I access /proxy, I cannot get the proxy results from end. image

I know that the return result is handled throughproxyRes, but what causes this difference?

kajweb avatar Dec 06 '23 12:12 kajweb