a simple multithreaded webserver
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

48 lines
1.5 KiB

#include <iostream>
#include <thread>
#include "webserver.hh"
int main()
{
std::cout << "serving http://127.0.0.1:8080/test.html\n";
pEp::Webserver web{net::ip::address::from_string("127.0.0.1"), 8080, "htdocs"};
std::cout << "adding handler for http://127.0.0.1:8080/handler/sample\n";
web.add_url_handler("/handler/(?<name>\\w+)",
[](boost::cmatch m, pEp::Webserver::request& req)->pEp::Webserver::response* {
pEp::Webserver::response *res = new pEp::Webserver::response;
// https://www.boost.org/doc/libs/1_73_0/libs/beast/doc/html/beast/ref/boost__beast__http__response.html
res->set(http::field::content_type, "text/json; charset=utf-8");
res->keep_alive(req.keep_alive());
res->body() =
"{"
"\"Herausgeber\": \"Xema\","
"\"Nummer\": \"1234-5678-9012-3456\","
"\"Deckung\": 2e+6,"
"\"Waehrung\": \"EURO\","
"\"Inhaber\":"
"{"
"\"Name\": \"Mustermann\","
"\"Vorname\": \"Max\","
"\"maennlich\": true,"
"\"Hobbys\": [\"Reiten\", \"Golfen\", \"Lesen\"],"
"\"Alter\": 42,"
"\"Kinder\": [],"
"\"Partner\": null"
"}"
"}";
res->prepare_payload();
return res;
}
);
web.run();
return 0;
}