Localhost dev server

Your own little fake internet


You are building some HTML page. You can do some things things with an HTML files on your hard disk, although these are locked down for security reasons.

So you run a local server to serve those files and have your browser treat them like part of the real internet.

Usually for local testing, serving the files unencrypted (plain HTTP) is enough; sometimes you need to do encrypted (keywords: HTTPS/SSL/TLS) which is a whole nother thing.

one-liners

There is a sport of writing HTTP server one-liners, and a mini site for them.

Here are two that are likely to work with no further fuss.

bareback

Bareback feature-free somehow-works HTTP with netcat:

nc -l 127.0.0.1 8889 < foo.html

python

This is reasonably simple and serves static files with little fuss.

python3 -m http.server --bind 127.0.0.1

Caddy

Caddy, is a free and open source server, and that will get you a long way. It has automatic SSL. It has plugins supporting totally OTT features such as AWS lambda function proxying and automatic hugo for plain text blogging.

caddy file-server --listen 127.0.0.1:2019

npm servers

For node browser apps, e.g. beefy and run-browser and their ilk might work and probably integrate with your build process. There are so many different options for node that I usually pass over it in choice-paralyzed silence.

Fenix is a GUI wrapped around a node-style server that promises advanced debugging/introspection features. But I haven’t used it and it doesn’t run on Linux, so ignoring for now.

Oh wait but I need SSL

Crap. I understand, but this is tricky in general. Perhaps you don’t truly need SSL? Most SSL-secured things are also available without SSL on localhost domain. Failing that, Caddy is probably easiest. See bonus tips under secure servers.

Bonus time: tunneling

ngrok is a service that allows you to inspect and replay web service requests from the internet to a local server for analysis.


Warning! Experimental comments system! If is does not work for you, let me know via the contact form.

No comments yet!

GitHub-flavored Markdown & a sane subset of HTML is supported.