I have a real server with REST APIs ready. Now I am developing an angular2 web application and want to consume real REST APIs in the development phase of the web application.
I am using angular-cli.
My server does not support cross origin access so I can not access the server REST api directly.
I need some way to put a request/response handler for my webpack development server.
It may be a silly question as I am trying nodejs world first time.
You should use 'cors' library to allow cross origin in your server
link: https://www.npmjs.com/package/cors
$ npm i -S cors
var cors = require('cors');
if you use express for example you should call 'use' function with cors:
app.use(cors());
Yair
Based on suggestions I written a proxy http handler with CORS enabled. This will simply take the request from the application and delegate to the actual server. Response from the actual server will be sent back to requesting web application. From the web application send the requests by just changing the base URL of server. Eg. instead of http://your_real_server.com/dashboard use http://localhost:7000/dashboard