miniserve
is a small HTTP server for testing websites on a development
computer. It doesn't do much, but it has a few features I wanted.
- URLs don't require
.html
. For example,miniserve
will look forbasedir/pretty-url
and, failing that, will try to servebasedir/pretty-url.html
. - Structured logging via
log/slog
. - Graceful shutdown, as much as possible.
- Optional flags can specify what port to serve on and what directory to
serve. (The defaults are 8080 and
"."
.)
My website uses pretty URLs (i.e., no .html
at the
end). On the server, nginx
takes care of all that, but I needed a way to
test the site at home. Once upon a time, I wrote a very ugly solution, but it
had no logging. I added logging using
Gorilla, but Gorilla recently stopped
being maintained. I took the
opportunity to write a fuller and better—though still miniature—server.
To be honest, I wrote this largely as an excuse to learn things. It does what I need well, but I wouldn't recommend it for anything serious. I wouldn't even recommend it to anyone but me even for trivial things. That said, if you have suggestions or criticisms, please file an issue.
Thanks to the authors of the following for inspiration and (often) code.
- Golang HTTP Server Graceful Shutdown
- http-server-shutdown.go
- Serve pages from links without
.html
- A Guide to Writing Logging Middleware in Go
- How I write HTTP services
- The http.Handler wrapper technique in #golang UPDATED
- Understanding http.HandlerFunc
- logfmt
- Using Canonical Log Lines for Online Visibility