Why is a proxy redirect working with Vite but not Koa?

I have the following in my vite.config…

export default {
  plugins: [vue(), loadVersion()],
  build: {
    chunkSizeWarningLimit: 1000,
  },

  server: {
    host: "0.0.0.0",
    port: 8080,
    proxy: {
      "/login": {
        target: coreUrl,
        changeOrigin: true,
      },
      "/logout": {
        target: coreUrl,
        changeOrigin: true,
      },
      "/userinfo": {
        target: coreUrl,
        changeOrigin: true,
      },
      "/g": {
        target: coreUrl,
        changeOrigin: true,
      },
      "/api": {
        target: coreUrl,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
};

And I have the following endpoint on the other side…

import { auth } from "express-openid-connect";
app.use(auth(jwtConfig));
app.get("/login", (req, res) => res.oidc.login({ returnTo: redirectUrl }));

When I run it this way and try to access http://<frontend IP>:<frontend port>/login, everything redirects correctly. However, we also need to be able to run using Koa so I try the following…

router.get('/login', proxy({
  url: `${coreUrl}/login`
}));

When the redirect happens I get an Auth0 error page stating…

Oops!, something went wrong

There could be a misconfiguration in the system or a service outage. We track these errors automatically, but if the problem persists feel free to contact us.
Please try again.

Why is it working with the vite proxy but not the koa one? Could this be related to it running on port 80?

I got it working by switching to koa-proxies…

const proxy = require("koa-proxies");
app.use(proxy("/login", {
  target: `${coreUrl}`,
  changeOrigin: true,
}));
1 Like

Wooah! Thanks for sharing that with the rest of community!