-
Notifications
You must be signed in to change notification settings - Fork 373
Home
qicosmos edited this page Jun 9, 2020
·
8 revisions
Welcome to the cinatra wiki!
cinatra::http_server* cinatra_web_server_;
cinatra_web_server_->set_transfer_type(transfer_type::ACCEPT_RANGES);
struct cross_origin
{
bool before(request &req, response &rep)
{
rep.add_header("Access-Control-Allow-Origin", "*");
rep.add_header("Access-Control-Allow-Credentials", "true");
if (req.get_method() == cinatra::method_name(cinatra::OPTIONS))
{
rep.add_header("Access-Control-Allow-Methods", "POST,GET,OPTIONS");
rep.add_header("Access-Control-Allow-Headers", "Content-Type,Origin,Accept");
rep.add_header("Access-Control-Max-Age", "120");
rep.set_status_and_content(cinatra::status_type::ok);
return false;
}
return true;
}
};
cinatra_web_server_->set_http_handler<http_method::GET, http_method::POST, http_method::OPTIONS>("/hello",
[this](request& req, response& rep) { rep.set_status_and_content(status_type::ok); }, cross_origin{});