Allow CORS in webserver

This commit is contained in:
Midgard 2021-09-19 03:50:03 +02:00
parent bc78ac5775
commit 72e5b663c5
Signed by: midgard
GPG key ID: 511C112F1331BBB4

View file

@ -277,6 +277,8 @@ int main(int argc, char** argv)
}
svr.Get("/api/segments.json", [](const httplib::Request &, httplib::Response &res) {
res.set_header("Access-Control-Allow-Origin", "*");
res.set_header("Access-Control-Allow-Methods", "GET");
json j;
int i = 0;
for (LedSegment* ledsegment : ledsegments) {
@ -293,6 +295,8 @@ int main(int argc, char** argv)
});
svr.Put("/api/code.json", [](const httplib::Request &req, httplib::Response &res, const httplib::ContentReader &content_reader) {
res.set_header("Access-Control-Allow-Origin", "*");
res.set_header("Access-Control-Allow-Methods", "PUT");
if (req.is_multipart_form_data()) {
res.set_content("No multipart forms allowed", "text/plain");
return true;
@ -316,6 +320,12 @@ int main(int argc, char** argv)
return true;
});
svr.Options("/api/code.json", [](const httplib::Request &req, httplib::Response &res) {
res.set_header("Access-Control-Allow-Origin", "*");
res.set_header("Access-Control-Allow-Methods", "PUT");
return true;
});
std::thread httpserverthread(starthttpserver);
ws2811_return_t ret;