Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic support for embedding/serving static content #17

Open
jeremypoulter opened this issue Feb 26, 2021 · 8 comments
Open

Generic support for embedding/serving static content #17

jeremypoulter opened this issue Feb 26, 2021 · 8 comments

Comments

@jeremypoulter
Copy link
Owner

jeremypoulter commented Feb 26, 2021

Move the code from https://github.com/OpenEVSE/ESP32_WiFi_V3.x/ for embeding/serving static content embedded into the firmware.

Maybe also consider alternative methods, eg https://github.com/Aircoookie/WLED

@jeremypoulter jeremypoulter changed the title Generic support for embedding/servicing static content Generic support for embedding/serving static content Feb 26, 2021
@ianrrees
Copy link

Mongoose, at least at v7.7, does have some support for this - see mg_http_serve_file(). It seems the paths they use rely on some basic filesystem-ish methods, which we may need to have for TLS support anyway.

@ianrrees
Copy link

which we may need to have for TLS support anyway.

Looks like we don't need that filesystem support for TLS, mongoose has got this clever shortcut for files that start with -, which the certs do: https://github.com/cesanta/mongoose/blob/76e6b23a4f0261dd534d33632f42ea1bba99dc85/mongoose.c#L5127-L5132

I don't think if their filesystem support is really appropriate for serving general static assets - it reads the whole file at once, in to a buffer allocated with calloc(). So, that mg_http_serve_file() method probably isn't useful for this.

@jeremypoulter
Copy link
Owner Author

That is rubbish, I think the code in the OpenEVSE works reasonably well. Doing a bit of work on the script to make it a bit more flexible (for the v2 UI). It would also be nice to support any Arduino filesystem as well, but this needs the ability to override the normal file system calls and replace with the Arduino equipment.

@zekageri
Copy link

zekageri commented Oct 3, 2023

You could start with the most common file system used by ESP Arduino, which is LittleFS.
It would be really awesome if we could throw a file system pointer to the static file serving method of mongoose or to the routes like in the case of Me no Dev's ESP async webserver.

fs::LittleFSFS sysFS;

server.serveStatic("/",sysFS,"/").setCacheControl(ONE_HOUR_CACHE_TIME);

server.on("/",HTTP_GET,[this](AsyncWebServerRequest *request){
    AsyncWebServerResponse *response =  request->beginResponse(
        sysFS,
        INDEX_PATH,
        "text/html"
    );
    response->addHeader("Content-Encoding", "gzip");
    request->send(response);
});

serveStatic method looks like this in this library

AsyncStaticWebHandler& AsyncWebServer::serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_control){
  AsyncStaticWebHandler* handler = new AsyncStaticWebHandler(uri, fs, path, cache_control);
  addHandler(handler);
  return *handler;
}

@johnnytolengo
Copy link

anyone could serve static files with LittleFS?

@jeremypoulter
Copy link
Owner Author

When you want to do OTA updates, it is convenient to merge the web UI files on to the firmware so you don't need a secondary process for updating them.

@johnnytolengo
Copy link

What I want is to serve a htnl files in littlefs

@jeremypoulter
Copy link
Owner Author

That is what the goal of #16 is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants