/** * OpenAPI Petstore * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. * * The version of the OpenAPI document: 1.0.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ #include "oatpp/web/server/HttpConnectionHandler.hpp" #include "oatpp/network/Server.hpp" #include "oatpp/network/tcp/server/ConnectionProvider.hpp" #include "oatpp/parser/json/mapping/ObjectMapper.hpp" #include "oatpp/parser/json/Utils.hpp" #include "PetApiController.hpp" #include "StoreApiController.hpp" #include "UserApiController.hpp" /** * Class which creates and holds Application components and registers components in oatpp::base::Environment * Order of components initialization is from top to bottom */ class AppComponent { public: /** * Create ConnectionProvider component which listens on the port */ OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionProvider)([] { return oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", 8080, oatpp::network::Address::IP_4}); }()); /** * Create Router component */ OATPP_CREATE_COMPONENT(std::shared_ptr, httpRouter)([] { return oatpp::web::server::HttpRouter::createShared(); }()); /** * Create ConnectionHandler component which uses Router component to route requests */ OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionHandler)([] { OATPP_COMPONENT(std::shared_ptr, router); // get Router component return oatpp::web::server::HttpConnectionHandler::createShared(router); }()); /** * Create ObjectMapper component to serialize/deserialize DTOs in Contoller's API */ OATPP_CREATE_COMPONENT(std::shared_ptr, apiObjectMapper)([] { return oatpp::parser::json::mapping::ObjectMapper::createShared(); }()); }; static int _main_app(void) { /* Register Components in scope of run() method */ AppComponent components; /* Get router component */ OATPP_COMPONENT(std::shared_ptr, router); /* Create PetApiController and add all of its endpoints to router */ auto PetApiController = std::make_shared(); router->addController(PetApiController); /* Create StoreApiController and add all of its endpoints to router */ auto StoreApiController = std::make_shared(); router->addController(StoreApiController); /* Create UserApiController and add all of its endpoints to router */ auto UserApiController = std::make_shared(); router->addController(UserApiController); /* Get connection handler component */ OATPP_COMPONENT(std::shared_ptr, connectionHandler); /* Get connection provider component */ OATPP_COMPONENT(std::shared_ptr, connectionProvider); /* Create server which takes provided TCP connections and passes them to HTTP connection handler */ oatpp::network::Server server(connectionProvider, connectionHandler); /* Print info about server port */ OATPP_LOGI("MyApp", "Server running on port %s", connectionProvider->getProperty("port").getData()); /* Run server */ server.run(); return 0; } int main(int argc, char **argv) { /* Init oatpp Environment */ oatpp::base::Environment::init(); int ret = _main_app(); /* Destroy oatpp Environment */ oatpp::base::Environment::destroy(); return ret; }