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

Swagger UI CORS problem #1156

Open
h1laryz opened this issue Aug 2, 2023 · 0 comments
Open

Swagger UI CORS problem #1156

h1laryz opened this issue Aug 2, 2023 · 0 comments

Comments

@h1laryz
Copy link

h1laryz commented Aug 2, 2023

When adding to swagger documentation any header (in my case x-api-key) getting error
Access to fetch at 'http://127.0.0.1:11600/........' from origin 'http://localhost:11500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Actually, I have this code

void RestApiServer::setupCors()
{
    pistacheRouter_.addMiddleware(
            []( const Pistache::Http::Request& request, Pistache::Http::ResponseWriter& writer )
            {
                writer.headers().add<Pistache::Http::Header::AccessControlAllowMethods>("GET,POST,DELETE,PUT,PATCH,OPTIONS");
                writer.headers().add<Pistache::Http::Header::AccessControlAllowHeaders>("x-api-key");  // tryed this 
                writer.headers().add<XApiKey>(); // tryed this 
                writer.headers().add< Pistache::Http::Header::AccessControlAllowOrigin >( "*" );
                return true;
            });
}

Also, without x-api-key header AccessControlAllowOrigin works fine can anyone help, please?

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

1 participant