How to switch an API endpoint from one environment to another?
Web developers often want to test the local changes directly on production websites — be it for debugging a production bug or for testing local changes before shipping code to production. Tools like Source Maps or Local Overrides don’t often work for this setup. With Requestly, you can map your production endpoints to local endpoints on your machine in less than a minute.
Use Requestly to switch production API endpoint to local
Suppose you have the production APIs on domain.com
, you can switch it to localhost:4001
using Requestly’s Replace rule. This will enable you to test your local changes on production.
- Install the Requestly browser extension and click on New Rule in the Top-Right.
- Next, Select the Replace String Rule from the list of rules. This should navigate you to the rule editor.
- Define for which requests you want the modifications to be made.
eg: If you want to replace
domain.com
withlocalhost:4001
- Save the rule and test if the endpoint has been switched on the configured site.
Possible CORS issue
Most production systems have very strict CORS policies, only allowing the production site to access the resources served. It is likely that CORS error will occur if you switch endpoints.
If you face any CORS issue, then you need the create a headers rule bypass the CORS headers. Please find more details on how to solve CORS errors here.