I am trying to set up a mock environments as follows inspired by this.
environment.mock.ts
export const environment = {
production: false,
PRODUCT_LIST : 'http://localhost:4200/app/mock-json/products.json',
SAVE_CART : 'http://localhost:4200/app/mock-json/cart.json'
};
environment.ts
export const environment = {
production: false,
PRODUCT_LIST : 'http://x.x.x.x:9000/service/products',
SAVE_CART : 'http://x.x.x.x:9000/service/cart'
};
Service Method
getCartData (request: string):Promise<Cart[]>{
return this.http.post(environment.SAVE_CART, request)
.toPromise()
.then(response => {
.....
})
.catch(this.handleError);
}
While I am running with ng serve then everything is running fine with original service endpoint.
But while I am using ng serve --environment=mock the Save Cart functionality is not working because of POST call. (All the GET call is working fine)
Actually I need to setup the structure in such a way that,
- using
ng serve. I could switch to original implementation which will use original service end points. - using
ng serve --environment=mockI could switch to mock implementation which will uses JSON files. - At the time of switching I do not need to touch any code. For mock implementation a set of predefined data will be serve always since my JSON file is hard coded.
Note: I have updated the main question to clarify the context what I am looking for. Same kind of error I am getting in this following Plunker (Please check console log). But note: this plunker does not implements the emvironments, so solving this plunker may not solve my problem.
{ "name" : "Test", "value" : "Test" }