// Copyright 2025 Jeisson Hidalgo-Cespedes. ECCI-UCR. CC-BY-4.0 #pragma once #include #include "HttpApp.hpp" /** * @brief Serve files found in static/ subfolder */ class StaticFileApp : public HttpApp { /// This object cannot be copied DISABLE_COPY(StaticFileApp); private: /// Directory where static files are located, by default "static/" subfolder. /// TODO(any): Configure it using config files, environment variables, or /// command line arguments std::filesystem::path documentRoot; public: /// Constructor StaticFileApp(); /// Destructor ~StaticFileApp() = default; /// @brief If the request is for a static file, serve it /// @return true if the request was handled, false otherwise bool handleHttpRequest(HttpRequest& httpRequest, HttpResponse& httpResponse) override; /// @brief Serve a static file /// @param path The full path to the file /// @param httpResponse The HTTP response object /// @return true if the file was served successfully, false otherwise bool serveFile(const std::filesystem::path& path, HttpResponse& httpResponse); /// Guess the MIME type from the file extension static std::string getMimeType(const std::filesystem::path& path); };