Improve webserver

This commit is contained in:
Fabian Müller 2024-03-31 20:53:33 +02:00
parent 32ba413380
commit 09e8e75edc

View File

@ -28,11 +28,6 @@ namespace {
<input type="text" name="text"> <input type="text" name="text">
</div> </div>
<div>
<label for="bright">Bright mode</label>
<input type="checkbox" name="bright">
</div>
<div> <div>
<button>Send</button> <button>Send</button>
</div> </div>
@ -45,7 +40,14 @@ namespace {
} }
void handleFormSend() { void handleFormSend() {
sendTextToSign("HELLO FORM"); String text = webServer.arg("text");
if (text.isEmpty()) {
webServer.send(404, "text/plain", "empty text");
return;
}
sendTextToSign(text);
// redirect back to root page // redirect back to root page
webServer.sendHeader("Location", "/"); webServer.sendHeader("Location", "/");
@ -54,7 +56,14 @@ namespace {
// RESTful API endpoint -- returns a proper status code rather than a redirect // RESTful API endpoint -- returns a proper status code rather than a redirect
void handleApiSend() { void handleApiSend() {
sendTextToSign("HELLO API"); String text = webServer.arg("text");
if (text.isEmpty()) {
webServer.send(404, "text/plain", "empty text");
return;
}
sendTextToSign(text);
webServer.send(200, "text/plain", "ok"); webServer.send(200, "text/plain", "ok");
} }
} }