add 404 handler, include css in header completely

This commit is contained in:
Marcus 2024-10-20 06:05:01 +02:00
parent 57fa57fc94
commit 5b54ae3658
5 changed files with 40 additions and 21 deletions

View file

@ -71,7 +71,7 @@ Config_System configSystem;
struct Config_Grow {
char growName[64];
char growName[64] = "CanGrow";
unsigned short dayOfGrow;
byte daysSeed;
byte daysVeg;

View file

@ -27,7 +27,10 @@
*
*/
/*
* include static files files
*/
#include "Webserver/File_cangrow_CSS.h"
/*
* include webpages header files
@ -40,10 +43,7 @@
#include "Webserver/Page_wifi.h"
/*
* include static files files
*/
#include "Webserver/File_cangrow_CSS.h"
AsyncWebServer webserver(80);
@ -51,9 +51,19 @@ AsyncWebServer webserver(80);
LoggingMiddleware requestLogger;
/* 404 error site - this is also a good example for a simple WebPage */
const char* Page_404_HTML PROGMEM = R"(%HEADER%
<div class='warnmsg'><h1>&#10071; &#65039; 404 - not found</h1></div>
%FOOTER%)";
/* processor */
String Proc_WebPage_404(const String& var) {
return AddHeaderFooter(var);
}
// https://github.com/mathieucarbou/ESPAsyncWebServer/blob/main/examples/SimpleServer/SimpleServer.ino
void WebserverNotFound(AsyncWebServerRequest* request) {
request->send(404, "text/plain", "Not found");
request->send(404, "text/html", Page_404_HTML, Proc_WebPage_404);
}
/*

View file

@ -28,19 +28,21 @@
*
*/
bool TestHeaderFooter(const String& var) {
#ifdef DEBUG
Serial.print(":: [Webserver:Page:root:proc:hf] var: ");
Serial.println(var);
#endif
if(var == "HEADER") {
return true;
} else if(var == "FOOTER") {
return true;
} else if(var == "CGVER") {
return true;
} else if(var == "CGBUILD") {
if(
(var == "HEADER") ||
(var == "FOOTER") ||
(var == "CGVER") ||
(var == "CGBUILD") ||
(var == "GROWNAME") ||
(var == "CANGROW_CSS")
) {
return true;
} else {
return false;
@ -56,6 +58,10 @@ String AddHeaderFooter(const String& var) {
return String(CANGROW_VER);
} else if(var == "CGBUILD") {
return String(CANGROW_BUILD);
} else if(var == "GROWNAME") {
return String(configGrow.growName);
} else if(var == "CANGROW_CSS") {
return String(File_cangrow_CSS);
} else {
return String();
}

View file

@ -35,7 +35,7 @@ const char* File_cangrow_CSS PROGMEM = R"(body {
}
.center {
width: 100%;
width: 100%%;
margin: auto;
}
@ -84,7 +84,7 @@ a:active {
}
.nav {
background: #333;
width: 100%;
width: 100%%;
margin: auto;
margin-bottom: 10px;
padding: 0;
@ -174,7 +174,7 @@ input[type=text], input[type=date], input[type=number], input[type=password], se
@media only screen and (min-width: 1820px) {
.center, .nav {
width: 60%; min-width: 420px;
width: 60%%; min-width: 420px;
}
.subnav li {
display: '';
@ -187,9 +187,8 @@ input[type=text], input[type=date], input[type=number], input[type=password], se
display: inline-block;
margin-bottom: 3px;
}
}
)";
})";
void WebFile_cangrow_CSS(AsyncWebServerRequest *request) {
request->send_P(200, "text/stylesheet", File_cangrow_CSS);
request->send_P(200, "text/css", File_cangrow_CSS);
}

View file

@ -34,9 +34,13 @@ const char* Header_HTML PROGMEM = R"(<!DOCTYPE html>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>CanGrow %CGVER% - %CGBUILD%</title>
<link rel='icon' href='data:;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAAsTAAALEwEAmpwYAAABcElEQVQ4y42TzU/bQBDFf7Nx1qGuAYVgQSuo2khBggPhyIH//9AiJAQ9tEeLqCKiUD6sxF52OMSEBCdW57aa9968fTsr3V5XWVLPO6sANNL7ZRAMNeU6Ea4T1UEI6pr55kcAwhpMrYOpk2/r/yEQmKWkIonf+TZVgex4Fw0bIEtIAALF3gbZ8U5VwKa3PJ18JT9IpiLvyflBwuhLG5veVUM0/0aoCONPa2hQjWZ8uEVeupJnXSBwO8YOH8iTeAKc2Q4Xt2C1VZL93F7MjbK/bxDnp5Zn7b+So+9pdQ+K/Q5qJlrRj5Ts6DM+rK7Ih7Mr3HaM7jYQVZqXQ6Tb6yqBYdTfomhHiFfUyMI3f+01/z7RHNzTGDyWGThP63SA2d8EEfIkrgQpzmOvH0AV+3M4zegNpUwagAYG8Yp4BS0nl4Kz5Mpf0JXJMby6w/66Aa+M+9uE53/Iexsggq4ESOYWC0jmsBfX8xdXhcJjL4cLc3kBl8uJGQ/CrpAAAAAASUVORK5CYII='>
<style>
%CANGROW_CSS%
</style>
</head>
<body>
<ul class='nav'><li><a href='/'>&#x1F331; Wohnzimmer Regal</a></li>
<ul class='nav'><li><a href='/'>&#x1F331; %GROWNAME%</a></li>
<li><a href='/growSettings' >&#128262; Grow settings</a></li>
<li><a href='/systemSettings' >&#9881; System settings</a></li>
<li><a href='/wifiSettings' class='activeMenu'>&#128225; WiFi settings</a></li>