I’m building on some of your web server ideas, and I have a website where I’d like to use authentication on a setup page. I have server.on() handlers for /setup and /setup.html to serve my setup.html page with authentication.
The problem is that serveStatic() is serving the setup.html page along with all the other static files. Can I tell serveStatic to ignore .html files? Or, can I some how set up serveStatic to just serve files from the css, images, and js directories in my LittleFS and ignore the root directory?
Hi.
I think you can serve static files from specific subdirectories.
For example, instead of referring the root directory “/”
server.serveStatic("/", LittleFS, "/");
You refer the directory where the files you want to serve are. Imagine you have the files in a folder called “static” in LittleFS:
server.serveStatic("/static/", LittleFS, "/static/");
I think this should work, but I didn’t test it.
Let me know your results.
Regards,
Sara
I learned something new today. The callback handlers are evaluated in the order created, so any resource you want to handle explicitly via server.on() needs to come before the serveStatic() handler. Probably obvious to most, but new to me.
That looks like it fixed most of my problem. If I need to, I’ll add another directory level for my static files like you suggested since there can be only on serveStatic() call.
Thank you, Sara!