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

How does one add header CORS in Pistache ? #51

Closed
GuacheSuede opened this issue Feb 26, 2017 · 8 comments
Closed

How does one add header CORS in Pistache ? #51

GuacheSuede opened this issue Feb 26, 2017 · 8 comments

Comments

@GuacheSuede
Copy link

Title is question, cannot seem to find any documentation on it. Thanks

@GuacheSuede
Copy link
Author

@oktal

@LaurentLouf
Copy link

Looking at the set of headers supported, it seems that Access-Control-Allow-Origin is not one of them, so you would have to add it following the documentation http://pistache.io/guide/#defining-your-own-header . I need it for a project too, so once tested, I'll probably send a PR with this header part of the official set of headers supported.

LaurentLouf pushed a commit to LaurentLouf/pistache that referenced this issue Mar 9, 2017
@LaurentLouf
Copy link

@GuacheSuede As you can see, this is fairly simple, then you just have to add a header as you would normally with Pistache. I think it has its place in the set of headers by default as it can be very useful for jQuery users that would like to use a REST API provided by Pistache (for example).

@GuacheSuede
Copy link
Author

Great, Thank you for the pull request.

@xinthose
Copy link

xinthose commented Nov 13, 2017

response.headers().add<Http::Header::AccessControlAllowOrigin>("*");
response.send(Pistache::Http::Code::Ok, "{\"message\":\"success\"}");

@msoodb
Copy link

msoodb commented Dec 30, 2018

response.headers().add<Http::Header::AccessControlAllowOrigin>("*");
response.send(Pistache::Http::Code::Ok, "{\"message\":\"success\"}");

Hi xinthose
i add this code to my doLigin() method, but nothings happen.
where should I add this code?

@xinthose
Copy link

response.headers().add<Http::Header::AccessControlAllowOrigin>("*");
response.send(Pistache::Http::Code::Ok, "{\"message\":\"success\"}");

Hi xinthose
i add this code to my doLigin() method, but nothings happen.
where should I add this code?

At the beginning of the route function. So like so:

void doLogin (const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response)
{
    response.headers().add<Pistache::Http::Header::AccessControlAllowOrigin>("*");

    // your code
}

@msoodb
Copy link

msoodb commented Dec 31, 2018

response.headers().add<Http::Header::AccessControlAllowOrigin>("*");
response.send(Pistache::Http::Code::Ok, "{\"message\":\"success\"}");

Hi xinthose
i add this code to my doLigin() method, but nothings happen.
where should I add this code?

At the beginning of the route function. So like so:

void doLogin (const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response)
{
    response.headers().add<Pistache::Http::Header::AccessControlAllowOrigin>("*");

    // your code
}

many thanks. this is very helpful.

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

4 participants