-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstaticfileserver.cpp
More file actions
29 lines (18 loc) · 923 Bytes
/
staticfileserver.cpp
File metadata and controls
29 lines (18 loc) · 923 Bytes
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
#include <oatpppre/StaticFilesHandler.hpp>
#include <oatpp/network/Server.hpp>
#include <iostream>
#include "StaticFileServerComponent.hpp"
int main(int argc, const char * argv[]) {
oatpp::base::Environment::init();
// Create typical oatpp scope Environment components
StaticFileServerComponent components;
auto router = components.httpRouter.getObject();
oatpppre::StaticFilesHandler::mountAtRoute(router, "/*", "."); // Add the static file handler
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, connectionHandler);
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, connectionProvider);
oatpp::network::Server server(connectionProvider, connectionHandler);
OATPP_LOGD("Server", "Running on port %s...", connectionProvider->getProperty("port").toString()->c_str());
server.run();
oatpp::base::Environment::destroy();
return 0;
}