| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #pragma once
- #include <string>
- #include <memory>
- #include <thread>
- #include <httplib.h>
- #include "auth/auth_middleware.hpp"
- namespace smartbotic::webserver {
- struct HttpServerConfig {
- int port = 8080;
- std::string static_files_path = "./webui/dist";
- int thread_pool_size = 8;
- };
- class HttpServer {
- public:
- explicit HttpServer(const HttpServerConfig& config);
- ~HttpServer();
- // Start/stop server
- void start();
- void stop();
- // Get underlying httplib server for route registration
- httplib::Server& server() { return server_; }
- // Register route with auth middleware
- void registerRoute(const std::string& method,
- const std::string& pattern,
- auth::AuthMiddleware::Handler handler,
- auth::AuthMiddleware* auth = nullptr,
- const std::string& required_role = "");
- // Static file serving setup
- void setupStaticFiles();
- bool isRunning() const { return running_; }
- private:
- HttpServerConfig config_;
- httplib::Server server_;
- std::thread server_thread_;
- bool running_ = false;
- };
- } // namespace smartbotic::webserver
|