#pragma once #include "esp_http_server.h" namespace kvida { // Allows a separately-hosted web app (kvida-sdk, e.g. served from // localhost:5173 via Vite during development) to call the device's JSON // API from a browser across origins. inline void add_cors_headers(httpd_req_t *req) { httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_set_hdr(req, "Access-Control-Allow-Methods", "GET, POST, OPTIONS"); httpd_resp_set_hdr(req, "Access-Control-Allow-Headers", "Content-Type"); } inline esp_err_t cors_preflight_handler(httpd_req_t *req) { add_cors_headers(req); httpd_resp_send(req, nullptr, 0); return ESP_OK; } } // namespace kvida