5 ms·
Ad hoc (one line) HTTP static servers in various programming languages https://gist.github.com/willurd/5720255 https://gist.github.com/willurd/5720255
by mtmail 6y ago
Ad hoc (one line) HTTP static servers in various programming languages https://gist.github.com/willurd/5720255 https://gist.github.com/willurd/5720255
- 1f60c 6y agoIt would be interesting if someone benchmarked them
- ComputerGuru 6y agoThey’re for dev purposes only; I think that would be testing for the wrong metric.
- alwillis 6y agoThanks; I was looking for just this a couple of days ago.
- userbinator 6y agoGood to see a netcat one show up there --- it is capable of serving only a single file, and you need to prepend the response headers yourself, but it's been very useful the few times I've had to use it.
- tdeck 6y agoI"be seen netcat used to support oauth login in some shell scripts.
- IgorPartola 6y agoMissed a couple: $ apache2 $ nginx My point is that while lots of languages include a web server in their standard library (one of these was a damn install! Like yes you can pip/gem/npm/etc install a server, that doesn’t make it a one line web server), it is by no means a one liner any more than the above two examples can be considered bash one liners.
- the_pwner224 6y agoOn practically any linux (or mac) you can do $ python -m http.server 8080 to instantly start up a server in that directory. You can do this in multiple terminals to have multiple servers on different ports serving multiple directories. Nginx, Apache require significant configuration and reboot to apply changes. They're not at all comparable.
- sgc 6y agoApache usually just needs to reload the config file not reboot, and it's also often only a few lines to get whatever you want done. Reload might take 1/2 a second, but I doubt it takes even that long. Sure, if you want to load a module with a bunch of new functionality you might need the 2 seconds it takes to reboot unless you have thousands of sites, but that has been a rare experience in the last 7 years or so for me. If you have thousands of sites you are not using python server anyway. In the end apache config is relatively easy -- especially to just test stuff quickly --, it's the overall server security that is more nebulous due to the variety of attack vectors throughout the stack. I would guess all that is similar on Nginx. So sure, it is a little easier to just throw out a one liner, but it doesn't give you an environment that is similar to deploy, so the extra 2 minutes to open the apache config and reload is worth it to me for the implicit bug testing going on. Of course none of us has a horse in the race and to each his own on his own box. But it's fair to keep their names in the conversation at least.
- Joker_vD 6y agoThat comes really handy when you want to, say, transfer some files from your PC to your phone/tablet without uploading them somewhere else first.