Intercepting Requests from Localhost

On macOS, any requests to localhost do not go through the configured proxy. To get around this we need to rename localhost to something else for it to be captured by Requestly. There are two ways you can do this

Solution 1: configure rq.proxy to point to localhost in /etc/hosts

  1. Open /etc/hosts as a sudo user . For eg. using sudo nano /etc/hosts . You will be prompted to enter your password

  2. Add the following entries to this file:

    127.0.0.1       rq.proxy
    ::1             rq.proxy
    
  3. Save the changes into this file.

  4. Replace all your calls to localhost with rq.proxy . For eg. http://localhost:3000http://rq.proxy:3000

  5. If you are using Chrome you might need to also stop automatic redirects from http → https for this domain:

    1. Go to chrome://flags

    2. search for the #unsafely-treat-insecure-origin-as-secure flag

    3. set the value as http://rq.proxy, http://localhost.requestly.io (the second domain is used in the next solution, incase this one doesn’t work)

Solution 2: Use localhost.requestly.io instead

We have setup this domain to point to 127.0.0.1 (i.e. your localhost). But for this to work you will have to follow the steps to stop automatic redirects from http → https.

As mentioned earlier, to do this in chrome:

  1. Go to chrome://flags

  2. search for the #unsafely-treat-insecure-origin-as-secure flag

  3. set the value as http://localhost.requestly.io

Once that’s done, replace all your calls to localhost with localhost.requestly.io . For eg. http://localhost:3000http://localhost.requestly.io:3000

Note: You might need to modify the source condition of any rules that were originally meant to be applied on localhost

Updated on