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));
});