From 09e8e75edc19789651455acee2fac9cd275de769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Sun, 31 Mar 2024 20:53:33 +0200 Subject: [PATCH] Improve webserver --- src/webserver.h | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/webserver.h b/src/webserver.h index f6d48c3..a9a1b45 100644 --- a/src/webserver.h +++ b/src/webserver.h @@ -28,11 +28,6 @@ namespace { -
- - -
-
@@ -45,7 +40,14 @@ namespace { } 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 webServer.sendHeader("Location", "/"); @@ -54,7 +56,14 @@ namespace { // RESTful API endpoint -- returns a proper status code rather than a redirect 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"); } }