cserver/examples/src/http.cpp

28 lines
1.1 KiB
C++
Raw Normal View History

2024-04-07 07:03:49 +00:00
#include <cserver/server/server/server.hpp>
#include <cserver/engine/basic/task_processor.hpp>
#include <cserver/server/handlers/http_handler_base.hpp>
2024-06-27 01:12:31 +00:00
struct SomeComponent : public cserver::server::handlers::HttpHandlerBaseWithAdder<SomeComponent> {
2024-04-07 07:03:49 +00:00
static constexpr utempl::ConstexprString kPath = "/v1/some/";
static constexpr utempl::ConstexprString kName = "name";
static constexpr utempl::ConstexprString kHandlerManagerName = "server";
inline constexpr SomeComponent(auto name, auto& context) :
2024-06-27 01:12:31 +00:00
HttpHandlerBaseWithAdder(name, context) {};
2024-04-07 07:03:49 +00:00
2024-06-27 01:12:31 +00:00
inline auto HandleRequestThrow(const cserver::server::http::HttpRequest& request) -> cserver::Task<cserver::server::http::HttpResponse> {
co_return cserver::server::http::HttpResponse{.body = request.url.data()};
2024-04-07 07:03:49 +00:00
};
};
auto main() -> int {
cserver::ServiceContextBuilder{}
.AppendConfigParam<"threads", 8>()
.AppendConfigParam<"server", cserver::ConstexprConfig{}
.Append<"taskProcessor">(utempl::ConstexprString{"basicTaskProcessor"})
.Append<"port">(55555)>()
.Append<cserver::server::server::Server<>>()
.Append<SomeComponent, "component">()
.Sort()
.Run();
};