Why does express-http-proxy seem to be ignoring the path?

652 Views Asked by At

I have the following...

const coreUrl = "myip:3000"
app.use('/login', proxy(coreUrl, options));

I would expect this to forward to myip:3000/login but it actually forwards to myip:3000 I also tried using coreUrl+"/login" as well but that didn't seem to help.

How do I redirect with the correct path using this tool?

2

There are 2 best solutions below

0
Heiko Theißen On

According to the documentation, the first argument to express-http-proxy is the host without a path. http-proxy seems to offer more options.

0
Jessitron On

I hit this today, and I found the "do things right" configuration. express-http-proxy strips the prefix that it matches from the path. There is a way to put it back on, with the proxyReqPathResolver option. Here is what worked:

import express from "express";
import proxy from "express-http-proxy";

const app = express();

app.use(
  "/login",
  proxy("http://localhost:4318", {
    proxyReqPathResolver: function (req) {
      return "/login" + req.url;
    },
  })
);