#include "crow.h"
#include "routes.h"
#include <cstdlib>
#include <stdexcept>
#include <string>

int main() {
    crow::SimpleApp app;

    // Serve static files from ./static
    // Crow serves them at /static/<path>

    // Register route groups
    routes::register_pages(app);
    routes::register_api(app);
    routes::register_system(app);
    routes::register_proxy(app);
    routes::register_mac(app);

    // Start server (port overridable via CXWEBAPP_PORT)
    int port = 8080;
    if (const char* p = std::getenv("CXWEBAPP_PORT")) {
        try { port = std::stoi(p); } catch (...) {}
    }
    CROW_LOG_INFO << "CxWebApp listening on :" << port;
    app.port(static_cast<uint16_t>(port))
       .multithreaded()
       .run();

    return 0;
}
