by umvi · 4y ago · 0 comments
For anyone looking for an easy way to spin up a command line web server, python has one built in, so if you are running linux usually you can do:
`python3 -m http.server`
From a terminal and it will spin up a web server that serves the current directory. I use this all the time for quick tinkering vs. installing/configuring nginx/node.js/caddy or whatever the cool kids are using these days.
This makes it really really not great when trying to serve pages (with various attending static files), or to ad-hoc share large resources with other people on the network.
It's fine if you're also evented, but that's not the case here, http.server literally can only interact with one connection at a time, the next connection(s) will be queued up waiting for http.server to finish its thing and accept them.
> My understanding anyway is that http.server is explicitly not for production use!
Sure, but "I'm at a lan party and have the installer for $game so we don't explode the 'net connection" is not the sort of "production use" that's intended by this statement.
Neither is "I want to open this HTML file I wrote which has a bunch of static assets booting up the webapp".
Looking at you HttpClient-on-esp8266...
https://stackoverflow.com/questions/12905426/what-is-a-faste...
Also, the python solution is only relevant if python is already installed. Something that's not true on Windows and is or will soon be true on MacOS.
Getting python up an running on Windows is fairly trivial though. You don't even need local admin permissions if your machine is locked down by your IT dept.
""" WARNING: Python 2.7 is not recommended. This version is included in macOS for compatibility with legacy software. Future versions of macOS will not include Python 2.7. Instead, it is recommended that you transition to using 'python3' from within Terminal. """
There is no version of Python 3 included with the OS. The XCode app/developer tools include Python 3.8. I expect macOS 13 won't include any Python interpreter out the box