123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #include "httpserver.h"
-
- bool HTTPServer::start() {
- if(!mount_fs()) {
- logf("cant mount filesystem, EXIT !\n\r");
- return false;
- }
- logf("[HTTPServer] LittleFS mounted !\n\r");
- logf("[HTTPServer] root:\n\r");
- this->listRoot();
- logf("\n\r");
-
- // default handler
- this->onNotFound([this]() {
- String message = "File Not Found\n\n";
- message += "URI: ";
- message += uri();
- message += "\nMethod: ";
- message += (method() == HTTP_GET) ? "GET" : "POST";
- message += "\nArguments: ";
- message += args();
- message += "\n";
-
- for (uint8_t i = 0; i < args(); i++) {
- message += " " + argName(i) + ": " + arg(i) + "\n";
- }
- send(404, "text/plain", message);
- });
-
- // add static root file handler for http
- this->serveStatic("/", LittleFS, "/");
-
- // application handler
- this->on("/app=terminal", HTTP_POST, [this]() {
- String log_msg = "terminal: millis: ";
- log_msg += millis();
- send(200, "text/plain", log_msg);
- });
-
- this->begin();
- Serial.printf("[HTTPServer] Server active on Port 80 !\n\r");
- }
|