Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

should middleware obtain the results of proxy? #75

Open
kajweb opened this issue Dec 6, 2023 · 0 comments
Open

should middleware obtain the results of proxy? #75

kajweb opened this issue Dec 6, 2023 · 0 comments

Comments

@kajweb
Copy link

kajweb commented Dec 6, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant