Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS #19

Open
riscie opened this issue Oct 29, 2014 · 2 comments
Open

CORS #19

riscie opened this issue Oct 29, 2014 · 2 comments

Comments

@riscie
Copy link

riscie commented Oct 29, 2014

Hi there! Great Project!

I have a question regarding how to disable the blocking of CORS requests.
I know that I can do someting like this which helps for all GET requests:
php header("Access-Control-Allow-Origin: *");
But I think there is a better option to do so which also includes POST requests?

Thank you in advance for any advice!

@riscie
Copy link
Author

riscie commented Oct 29, 2014

So this helped me:

    // Allow from any origin
    if (isset($_SERVER['HTTP_ORIGIN'])) {
        header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
        header('Access-Control-Allow-Credentials: true');
        header('Access-Control-Max-Age: 86400');    // cache for 1 day
    }

    // Access-Control headers are received during OPTIONS requests
    if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
            header("Access-Control-Allow-Methods: GET, POST, OPTIONS, DELETE");         

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
            header("Access-Control-Allow-Headers:        {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

        exit(0);
    }

(Source: http://stackoverflow.com/questions/18382740/cors-not-working-php)
That this will now accept requests from diffrent sources. I needed this in a project created with yeoman where the yeoman generator utilized two diffrent webservers. (One for the app and one for the api).

Maybe this helps someone else. (It's a non-issue. Sorry if posting here was wrong...)

@alixaxel
Copy link
Owner

Thanks for the suggestion and the solution @riscie, I will consider making this the default behavior.

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

No branches or pull requests

2 participants