Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Getting not allowed by Access-Control-Allow-Origin error #32

Closed
gregmercer opened this issue May 26, 2013 · 5 comments
Closed

Getting not allowed by Access-Control-Allow-Origin error #32

gregmercer opened this issue May 26, 2013 · 5 comments

Comments

@gregmercer
Copy link

When I try to load the http://localhost:9000/#/recipe/1 page from the client server I get the following error:

XMLHttpRequest cannot load http://copelandia.localhost:8082/node/1. Origin http://localhost:9000 is not allowed by Access-Control-Allow-Origin. localhost:1
Error: Error while interpolating: {{getImage(recipe)}}
TypeError: Cannot read property 'length' of undefined
at Error ()
at Object.k (https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:54:410)
at Object.e.$digest (https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:89:233)
at Object.e.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:91:431)
at f (https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:100:38)
at B (https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:103:323)
at XMLHttpRequest.p.onreadystatechange (https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:104:455)

I've tried uncommenting this to the .htaccess file, but not luck.

Header set Access-Control-Allow-Origin "*"

Any ideas on how to get around this?

Thanks,
Greg

@sirkitree
Copy link
Contributor

I take it this is when trying to use the AngularJS client? Are you also running the Drupal instance locally? SOme more details on your setup should help.

@gregmercer
Copy link
Author

Yes, I'm trying to run the AngularJS client using the grunt server. I using the "grunt server" command and the setup mentioned on this page:
https://github.com/Lullabot/copelandia/tree/master/clients/angularjs

On the same local machine, under a different port, I run a local Drupal instance. The server is setup/run using the Acquia Dev Desktop Control Panel app. The Desktop runs Apache (mod_php) with Php 5.4.8

@sirkitree
Copy link
Contributor

The CORS module is included in this repo's Drupal installation and should be enabled on your Drupal site. This can be configured to allow any other domain or site to access by going to /admin/config/services/cors and setting the "Domains" value to *|*.

Once this is setup and configured it should allow XHRs from anywhere. Please let me know if this fixes the issue.

@gregmercer
Copy link
Author

Enabling and configuring the CORS module as you mentioned worked.

I also needed to set the following permission for the anonymous user:
RESTful web services
Access the resource node

Thanks very much for all your help. :)

@sirkitree
Copy link
Contributor

We should either add this to the copelandia_rest feature or get it documented. Re-opening.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants