Coder Social home page Coder Social logo

Comments (8)

LaurentLouf avatar LaurentLouf commented on July 16, 2024 2

@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).

from pistache.

xinthose avatar xinthose commented on July 16, 2024 2
response.headers().add<Http::Header::AccessControlAllowOrigin>("*");
response.send(Pistache::Http::Code::Ok, "{\"message\":\"success\"}");

from pistache.

msoodb avatar msoodb commented on July 16, 2024 1
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.

from pistache.

GuacheSuede avatar GuacheSuede commented on July 16, 2024

@oktal

from pistache.

LaurentLouf avatar LaurentLouf commented on July 16, 2024

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.

from pistache.

GuacheSuede avatar GuacheSuede commented on July 16, 2024

Great, Thank you for the pull request.

from pistache.

msoodb avatar msoodb commented on July 16, 2024
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?

from pistache.

xinthose avatar xinthose commented on July 16, 2024
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
}

from pistache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.