#pragma once // Application: composition root. Owns routers, middleware chain, sub-app // mounts, and the typed error mapping. Gap: real molo::app::Application in // 05-request-routing.md owns lifespan hooks, plugin registry, and the full DI // container; this skeleton passes a Services struct to route factories. #include #include #include #include #include "Http.hpp" #include "Router.hpp" namespace molo::example::fw { enum class MiddlewareSlot { Errors = 0, Observability = 1, Security = 2, SessionAuth = 3, User = 4, }; using Next = std::function; using Middleware = std::function; class HttpError { public: HttpError(int status, std::string code, std::string message); int status() const; const std::string& code() const; const std::string& message() const; private: int status_; std::string code_; std::string message_; }; class Application : public std::enable_shared_from_this { public: void use(MiddlewareSlot slot, Middleware middleware); void include_router(const std::string& prefix, const Router& router, const std::string& name_prefix = ""); void mount(const std::string& path, std::shared_ptr sub); Response dispatch(Request req); const std::vector& routes() const; private: Response dispatch_inner(Request req, int depth); Response run_chain(Request req, int depth); Router router_; std::vector> middlewares_; std::vector>> mounts_; MiddlewareSlot last_slot_ = MiddlewareSlot::Errors; bool has_middleware_ = false; }; Middleware errors_middleware(); Middleware request_id_middleware(); } // namespace molo::example::fw