• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Any way to exclude files from ESPAsync serveStatic()

Q&A Forum › Category: ESP32 › Any way to exclude files from ESPAsync serveStatic()
0 Vote Up Vote Down
Tom Blough asked 2 weeks ago

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?

3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 2 weeks ago

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

0 Vote Up Vote Down
Tom Blough answered 2 weeks ago

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!

0 Vote Up Vote Down
Sara Santos Staff answered 2 weeks ago

Ok.
Great!
I’ll mark this issue as resolved. If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn LVGL: Build GUIs for ESP32 Projects – Version 1.5 July 7, 2025
  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.