-
Notifications
You must be signed in to change notification settings - Fork 28
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 error #102
Comments
What I have found is that the notFoundHandler does not capture Right now it looks like this: DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*");
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept");
// Return 200 for OPTIONS type
server.on("/getSysInfo", HTTP_OPTIONS, [](PsychicRequest *request) {
return request->reply(200);
});
// Handle the actual request
server.on("/getSysInfo",HTTP_GET,[](PsychicRequest *request){
}); This is a really bad design since I must make a copy of every handler in my app. @hoeken Is this possible somehow? |
server.on("/*", HTTP_OPTIONS, [](PsychicRequest *request) {
printf(
"\n[Server] - OPTIONS\nURL: %s\nMethod: %s\nBody: %s\n",
request->url().c_str(),
request->methodStr().c_str(),
request->body().c_str()
);
return request->reply(200);
}); |
Hi! I'm wondering how to bypass CORS errors.
I have added these default headers to my server:
I have also setup my notfound handler like this so it will return a 200 OK response if the method is
HTTP_OPTIONS
But I still get CORS error in the browser. Any more ideas? I have also tried to create a new response object, set these headers and send that response instead of replying to the request. Did not work.
The text was updated successfully, but these errors were encountered: