Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
createProxyMiddleware: pathRewrite does not work

I would forward from /api/getUser to /getUser endpoint. Locally it works, but remotelly not, remotelly it sends to /api/getUser, why?

heroku[router]: at=info method=POST path="/api/getUser" host=speechifai-poc.herokuapp.com request_id=f6f155e0-2ab0-4a6e-a0cd-354557d0fcdd fwd="58.97.222.40" dyno=web.1 connect=0ms service=1ms status=404 bytes=588 protocol=https

I can adjust wether targeting local / remote by setting false / true.

if (false) {
  axios.defaults.baseURL = "http://localhost:3000/api/";
} else {
  axios.defaults.baseURL = "https://speechifai-poc.herokuapp.com/api/";
}
const { createProxyMiddleware } = require("http-proxy-middleware");

module.exports = function (app) {
  app.use(
    "/api",
    createProxyMiddleware({
      target: false
        ? "http://localhost:8080"
        : "https://speechifai-poc.herokuapp.com",
      changeOrigin: true,
      pathRewrite: {
        "^/api": "/", // rewrite path
      },
    })
  );
};

I have:

"http-proxy-middleware": "^2.0.3",

And I call here with axios:

axios({
  method: "post",
  url: "getUser",
  data: {},
  headers: { crossDomain: true },
}).then((res) => {
  dispatch(setGetUser(res.data));
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!