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

Multiple Access-Control-Allow-Origin Headers #115

Open
m-schreiber opened this issue Oct 15, 2018 · 2 comments
Open

Multiple Access-Control-Allow-Origin Headers #115

m-schreiber opened this issue Oct 15, 2018 · 2 comments

Comments

@m-schreiber
Copy link

Hi There,
just hit a Problem - would be nice if you could implement it.

Multiple "Access-Control-Allow-Origin"-Headers are not allowed:
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSMultipleAllowOriginNotAllowed

Instead of

foreach($allowedOrigin as $allowed_origin) { // to support multiple origins
	header("Access-Control-Allow-Origin: $allowed_origin");
}

do

header("Access-Control-Allow-Origin: ".implode(", ",$allowed_origin);
@jacwright
Copy link
Owner

Let me know if #116 works for you.

@m-schreiber
Copy link
Author

yes - this should work for me - will get back if i integrate a new version of your rest-server into my project - but my workaround looks and works the same:

$server = new \Jacwright\RestServer\RestServer($config["mode"]);
$server->useCors = false;
$server->allowedOrigin = $config["allowedOrigin"];

$server->addClass(...);

header("Access-Control-Allow-Origin: ".implode(", ",$config["allowedOrigin"]));
header('Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS');
header('Access-Control-Allow-Credential: true');
header('Access-Control-Allow-Headers: X-Requested-With, content-type, access-control-allow-origin, access-control-allow-methods, access-control-allow-headers, Authorization');
if ($server->getMethod() == 'OPTIONS')
{
    //Exit because of Bug in RestServer that makes it crash when not using cors
    exit;
}

$server->handle();

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

No branches or pull requests

2 participants