The requested resource does not have an "Access-Control-Allow-Origin" header. Origin "http: // localhost" is therefore not allowed

I have an app in AngularJS (ionic framework) and a server in Symfony.

In local mode everything works, but now I am doing my tests with a server on the internet. Unfortunately things are not the same as locally, I have the following error:

No "Access-Control-Allow-Origin" header is present on the requested resource. Therefore, the original address http: // localhost 'is not allowed.

I was wondering how to add the "Access-Control-Allow-Origin" CORS header which is missing.

+3


source to share


2 answers


Use this bundle: NelmioCorsBundle



CORS-Bundle is used to define CORS rules. This package allows you to define which domains will have access to your REST API. And it will make your job easier :)

+1


source


I don't think your problem came from Angular, it looks like it comes from your API server.

You might need a server-side headers:



Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS

      

+1


source







All Articles