Extend "ionic serve" to serve as a fake or delegate http server

Hi, there

I’m developing an app with ionic, and “ionic serve” is great for UI part, cause it could run on a browser. I’m going to load data from server, and the browser get errors like: “XMLHttpRequest cannot load *** . No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8100’ is therefore not allowed access.”

We could overcome it by using simulator, however it’s not convenient cause it’s not easy to debug on simulator.

Since “ionic serve” already starts a simple web server, so another idea is to extend “ionic serve” and return sample data from this server, in this way it could be quite easy as we could debug it from a browser.

Don’t know if any one has tried this way or whether it’s possible. Any feedback is highly appreciated.

What I’m doing is that I have a mock API coded into the angular app, and a service that either returns that or the real API depending on settings. It’s especially great for protractor tests.

I’m unsure of how reasonable it is to return extra data for the ionic serve server, since you’d either return static JSON/something from a predetermined folder, or if you need logic you’d need to actually code a fake server.

I think the first option is somewhat reasonable, but so limited in scope that it would be a rather thankless time investment compared with bigger ionic features.

Is there a guide or tutorial that you followed for the mock API? We have been looking into similar solutions for our protractor CI tests such as vcr.js and sepia to at least play back server responses so our tests run faster but without any luck.

I just mostly used https://docs.angularjs.org/api/ngMock/service/$httpBackend.