Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes CORS for meshtasticd to allow use of clients on other origins #5463

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/mesh/raspihttp/PiWebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ int handleAPIv1ToRadio(const struct _u_request *req, struct _u_response *res, vo
ulfius_add_header_to_response(res, "X-Protobuf-Schema",
"https://raw.githubusercontent.com/meshtastic/protobufs/master/meshtastic/mesh.proto");

if (req->http_verb == "OPTIONS") {
if (strcmp(req->http_verb, "OPTIONS") == 0) {
ulfius_set_response_properties(res, U_OPT_STATUS, 204);
return U_CALLBACK_CONTINUE;
return U_CALLBACK_COMPLETE;
}

byte buffer[MAX_TO_FROM_RADIO_SIZE];
Expand Down Expand Up @@ -269,6 +269,11 @@ int handleAPIv1FromRadio(const struct _u_request *req, struct _u_response *res,
ulfius_add_header_to_response(res, "X-Protobuf-Schema",
"https://raw.githubusercontent.com/meshtastic/protobufs/master/meshtastic/mesh.proto");

if (strcmp(req->http_verb, "OPTIONS") == 0) {
ulfius_set_response_properties(res, U_OPT_STATUS, 204);
return U_CALLBACK_COMPLETE;
}

uint8_t txBuf[MAX_STREAM_BUF_SIZE];
uint32_t len = 1;

Expand Down Expand Up @@ -493,7 +498,9 @@ PiWebServerThread::PiWebServerThread()
// Maximum body size sent by the client is 1 Kb
instanceWeb.max_post_body_size = 1024;
ulfius_add_endpoint_by_val(&instanceWeb, "GET", PREFIX, "/api/v1/fromradio/*", 1, &handleAPIv1FromRadio, NULL);
ulfius_add_endpoint_by_val(&instanceWeb, "OPTIONS", PREFIX, "/api/v1/fromradio/*", 1, &handleAPIv1FromRadio, NULL);
ulfius_add_endpoint_by_val(&instanceWeb, "PUT", PREFIX, "/api/v1/toradio/*", 1, &handleAPIv1ToRadio, configWeb.rootPath);
ulfius_add_endpoint_by_val(&instanceWeb, "OPTIONS", PREFIX, "/api/v1/toradio/*", 1, &handleAPIv1ToRadio, NULL);

// Add callback function to all endpoints for the Web Server
ulfius_add_endpoint_by_val(&instanceWeb, "GET", NULL, "/*", 2, &callback_static_file, &configWeb);
Expand Down