-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
42 lines (35 loc) · 1.1 KB
/
main.cpp
File metadata and controls
42 lines (35 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "Poco/Net/HTTPServer.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
#include "Poco/Net/ServerSocket.h"
#include "Poco/Util/ServerApplication.h"
#include "src/handlers/APIRequestHandler.hpp"
#include <vector>
class APIRequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory
{
public:
Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &request) override
{
return new APIRequestHandler;
}
};
class WebServerApp : public Poco::Util::ServerApplication
{
protected:
int main(const std::vector<std::string> &args) override
{
unsigned short port = 8080;
Poco::Net::ServerSocket svs(port);
Poco::Net::HTTPServer srv(new APIRequestHandlerFactory, svs, new Poco::Net::HTTPServerParams);
srv.start();
logger().information("Server started on port %hu.", port);
waitForTerminationRequest();
logger().information("Stopping server...");
srv.stop();
return Application::EXIT_OK;
}
};
int main(int argc, char **argv)
{
WebServerApp app;
return app.run(argc, argv);
}