Skip to content

Commit

Permalink
prevent CORS issue...?
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenWizard2015 committed Jan 5, 2024
1 parent 267322c commit eade444
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions controller/tea_poor/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ CommandProcessor commandProcessor(
waterPump
);

void withExtraHeaders(Response &res) {
res.set("Access-Control-Allow-Origin", "*");
res.set("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, PATCH, DELETE");
res.set("Access-Control-Allow-Headers", "Content-Type");
res.set("Content-Type", "application/json");
}

void setup() {
Serial.begin(9600);
waterPump->setup();
Expand All @@ -37,16 +44,19 @@ void setup() {
req.query("milliseconds", milliseconds, 64);

const auto response = commandProcessor.pour_tea(milliseconds);
withExtraHeaders(res);
res.print(response.c_str());
});
// stop water pump
app.get("/stop", [](Request &req, Response &res) {
const auto response = commandProcessor.stop();
withExtraHeaders(res);
res.print(response.c_str());
});
// get system status
app.get("/status", [](Request &req, Response &res) {
const auto response = commandProcessor.status();
withExtraHeaders(res);
res.print(response.c_str());
});
});
Expand Down

0 comments on commit eade444

Please sign in to comment.