I have a react app started with CRA, and a backend server set up for my react app.
My fetch requests go something like
const res = await fetch("/applications", {
...
I have set it up my app with a proxy middleware using http-proxy-middleware
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
app.use(
createProxyMiddleware({
target: 'https://projects.mydomain.com/',
changeOrigin: true,
})
);
};
When I make a request to the backend using fetch("/applications")
my request get's parsed as fetch("/projects.mydomain.com/applications")
However I need to add a url path to the begining of all my fetch requests, my final desired result is:
fetch("/projects.mydomain.com/b2b-iys/applications")
I tried doing this:
app.use(
'/b2b-iys/',
createProxyMiddleware("/b2b-iys", {
target: 'https://projects.muhammed-aldulaimi.com/',
changeOrigin: true,
})
);
But that didn't work.
I would ideally like to add it to my proxy rather than change the files one by one.
What's the solution here?