Reputation: 526
I have an application in AngularJS (ionic framework), and a server in Symfony.
In local everything works, but now I do my tests with the server online. Unfortunately everything does not happen like local, I have the following error:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http: // localhost' is therefore not allowed access.
I was wondering how to add the "Access-Control-Allow-Origin" CORS header that is missing.
Upvotes: 3
Views: 629
Reputation: 651
Use this bundle: NelmioCorsBundle
The CORS-Bundle is used to define the CORS rules. This bundle allows you to define which domains will have access to your REST API. And it will make your job easier too :)
Upvotes: 1
Reputation: 18279
I don't think your issue came from Angular, it looks like it comes from your API server.
You may need some headers server side:
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Upvotes: 1