#ifndef APPLICATION_H #define APPLICATION_H #include "object.h" #include #include #include #include #include #include #include #include "handler_instance.h" #include "core/http_server_callbacks.h" class Request; class ListenerManager; class Application { public: static std::string default_error_404_body; static std::string default_generic_error_body; static void handle_request(Request *request); static void send_error(int error_code, Request *request); static void send_file(const std::string &path, Request *request); static void default_fallback_error_handler(int error_code, Request *request); static void default_404_error_handler(int error_code, Request *request); virtual void load_settings(); virtual void setup_routes(); virtual void setup_middleware(); static void default_routing_middleware(Object *instance, Request *request); virtual void migrate(); virtual void run(); trantor::EventLoop *get_loop() const; void onAsyncRequest(const HttpRequestPtr &req, std::function &&callback); void onNewWebsockRequest(const HttpRequestPtr &req, std::function &&callback, const WebSocketConnectionPtr &wsConnPtr); void onConnection(const trantor::TcpConnectionPtr &conn); Application(); virtual ~Application(); static Application *get_instance(); std::unique_ptr listenerManagerPtr_; public: static HandlerInstance index_func; static std::map main_route_map; static std::vector middlewares; static std::map > error_handler_map; static std::function default_error_handler_func; size_t idleConnectionTimeout_; size_t threadNum_; std::string sslCertPath_; std::string sslKeyPath_; std::vector > syncAdvices_; private: static Application *_instance; bool _running; }; #endif