0

I am running my angular 2 app with node And back-end with Wildfly server. Both are running on different servers( On same machine). I need to make a call to API from front-end for retrieving data. Will it work?

pavan
  • 1
  • 2
  • https://angular.io/docs/ts/latest/guide/server-communication.html – stijn.aerts Sep 22 '16 at 06:48
  • I just gone through the above link #stijn26 while accessing remote server it is giving error like : XMLHttpRequest cannot load http://Post-method link in back-end. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3008' is therefore not allowed access. – pavan Sep 22 '16 at 07:06
  • http://stackoverflow.com/questions/39169785/understanding-cors-handling-for-external-service-in-angular2 – Supamiu Sep 22 '16 at 07:20

1 Answers1

0

In development environment; you can proxy your angular2 app router to your api port and path;

for example:

you can use webpack-server proxy config:

devServer: {
        changeOrigin: true,
        historyApiFallback: true,
        proxy: {


        '/api/v1/*': {
            target: 'http://localhost:3000',
        },
        '/api/v2/*': {
            target: 'http://localhost:3000',
        }

    }

}
junk
  • 917
  • 3
  • 11
  • 29