I would like to run a mock server e.g. JSON Server, and switch between my real Java REST API backend and this JSON Server during development (for instance when real backend services are down). Is there a way to easily configure angular to use a different host for all request?
My setup:
And I would like to switch between calls to localhost:8080/api
and localhost:9090/api
with one singe line for whole Angular application.
@PetrAveryanov gave me hint. Using json-proxy
this is as easy as launching proxy:
json-proxy -p 8081 -f "/api=http://localhost:9090" -f "/=http://localhost:8080"
And accessing application via port 8081
. "Regular" requests will be still passed through to 8080
(Tomcat serving Spring MVC application). All API calls will go to 9090
(JSON Server).