async-esp-fs-webserver
async-esp-fs-webserver copied to clipboard
template procesing replace
hello
have a problem template procesing replace on uploadhtmlfile that works
but iti salso performed on the ace editor html content
so the edited html is not the file with %STATE% %MDNS% %IP%
but editor content is filled in with the data for %STATE% %MDNS% %IP%
editor content source should not be processed
anyone has an idea?
server.on("/bulb.html", HTTP_GET, [](AsyncWebServerRequest * request) {
if (request->url() != "/ace") {
String path = "/bulb.html"; // Directly specify the file path
String contentType = "text/html"; // We know it's an HTML file
File file = LittleFS.open(path, "r");
if (!file) {
request->send(404, "text/html", "Oh No, Not found <a href=\"/\">/ home</a>");
return;
}
String fileContent = file.readString();
file.close();
// Perform dynamic content replacement
fileContent.replace("%STATE%", ledState ? "ON" : "OFF");
fileContent.replace("%MDNS%", String(myhostname) + ".local");
fileContent.replace("%IP%", WiFi.localIP().toString());
request->send(200, contentType, fileContent);
}
});
<!DOCTYPE html>
<html>
<head>
<title>garage.local Dynamic Iframes from mDNS WebSocket Data</title>
should be in editor
<!DOCTYPE html>
<html>
<head>
<title>%MDNS% Dynamic Iframes from mDNS WebSocket Data</title>
think this looks if referer is my ace editor do not do %% template processing in ace editor content load
https://github.com/ldijkman/async-esp-fs-webserver/blob/master/docs/ino/ESP8266.ino
server.on("/bulb.html", HTTP_GET, [](AsyncWebServerRequest * request) {
if (request->hasHeader("Referer")) {
AsyncWebHeader* refererHeader = request->getHeader("Referer");
String refererValue = refererHeader->value();
Serial.print("Referer: ");
Serial.println(refererValue);
// Check if the Referer does not contain "/ace"
if (refererValue.indexOf("/ace") != -1) {
if (LittleFS.exists("/bulb.html")) {
Serial.println("bulb.html exists. Serving it now...");
request->send(LittleFS, "/bulb.html", "text/html");
}
} else {
String path = "/bulb.html"; // Directly specify the file path
String contentType = "text/html"; // We know it's an HTML file
File file = LittleFS.open(path, "r");
if (!file) {
request->send(404, "text/html", "Oh No, Not found <a href=\"/\">/ home</a>");
return;
}
String fileContent = file.readString();
file.close();
// Perform dynamic content replacement
fileContent.replace("%STATE%", ledState ? "ON" : "OFF");
fileContent.replace("%MDNS%", String(myhostname) + ".local");
fileContent.replace("%IP%", WiFi.localIP().toString());
request->send(200, contentType, fileContent);
}
}
});
%MDNS% is not processed
in /edit the %MDNS% is still processed