rubypumaadsf

How to make ADSF/Puma serve HTML files without the .html extension


I am building a static site without the help of Jekyll or any other known static site builder. When deploying such site to a static site host like GitHub Pages or Netlify, these servers know to load software.html when I am accessing mydomain.com/software (without the .html extension).

Is there a way for me to reproduce this behavior when running a local, Ruby-based web server such as Puma? More specifically, I am using Ruby's adsf wrapper to launch a Puma server to serve my site locally for development.

My guess is that this should be possible by some rack middleware or rack configuration, I am just unable to identify the proper Google search for it.

I should probably mention that I am not interested in the directory/index.html approach, since all web servers I have seen add a trailing slash to the URL in these cases.


Solution

  • https://github.com/tommysundstrom/middleman-rack-optional-html might help.

    actually the code is simple. add ".html" extention if the path doesn't end with "html".

    https://github.com/tommysundstrom/middleman-rack-optional-html/blob/df1e50beca7599f3e47c5b83887573434f3253e3/lib/rack/middleman/optional_html.rb#L50