#ifndef __CORS_H__ #define __CORS_H__ #include "crow.h" #include "json_settings.h" extern AppSettings::Settings settings; struct CORS { // required inner type for Crow middleware struct context {}; void before_handle(crow::request& req, crow::response& res, context& /*ctx*/) { // allow all origins (for dev); replace "*" with your frontend URL in production res.add_header("Access-Control-Allow-Origin", settings.url); res.add_header("Access-Control-Allow-Methods", "POST, GET, OPTIONS"); res.add_header("Access-Control-Allow-Headers", "Content-Type"); // automatically handle preflight if (req.method == crow::HTTPMethod::OPTIONS) { res.end(); // stop here — no routing needed } } // run after handler (not needed for CORS, but must be present) void after_handle(crow::request&, crow::response&, context&) {} }; #endif // __CORS_H__