AlexisCraig
AlexisCraig

Reputation: 526

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access

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

Answers (2)

DaxDev
DaxDev

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

Mistalis
Mistalis

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

Related Questions