0

I am on http://localhost:8081/post URL and my API is hosted at some "http://dummy.restapiexample.com/api/v1".

I want it to appear in the network tab like "/custom/create". But the network tab is showing "http://localhost:8081/custom/create" but it should not append localhost URL in that. It should take the hosted API URL.

I am using CRA boilerplate. And I do not want to use express for the same.

I tried the following code

const proxy = require("http-proxy-middleware");

module.exports = function(app) {
    app.use(proxy("/custom",
    {target: "http://dummy.restapiexample.com/api/v1"}));
};

and in for API calls, I am using below format:

fetch('/custom/create', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(authData),
})

I am not getting how to hide the whole Hosted API URL and show proxy URL in the network tab.

Please give your valuable suggestion over this.

I am a novice in proxy-middleware. Thank you in advance :)

Shamrai Aleksander
  • 13,096
  • 3
  • 24
  • 31

1 Answers1

0

In your package.json include the url of your API as a proxy.

  "proxy": "http://dummy.restapiexample.com",
Muljayan
  • 3,588
  • 10
  • 30
  • 54