Live data from Hacker News

Big list of HTTP static server one-liners

gist.github.com

21–30 of 100 posts

Re: Big list of HTTP static server one-liners

#21
post #7

I'm always surprised that nginx doesn't have a nice way to run as a single-liner command.

I think it makes sense since it is completely driven by its config and adheres to the Unix philosophy of doing one thing well and not clutter the binary with additional stuff for fringe use cases. It would make the now surprisingly simple cli arguments more complex.

It should be trivial to write a shell script or alias that templates `root $(pwd);` and invokes `nginx -c /tmp/nginx.conf`

Re: Big list of HTTP static server one-liners

#23
post #7

I'm always surprised that nginx doesn't have a nice way to run as a single-liner command.

What would be the use case? These are useful for experimenting and doing something ad-hoc, but once you deploy to a serious environment not being a one-liner is irrelevant. On the other hand supporting that special case has its own costs.

Re: Big list of HTTP static server one-liners

#25

The ruby one with the -run option is a bit nonintuitive in how it works. $ ruby -run -ehttpd . -p8000 The -r option requires un.rb[1] which is a file full of convenience functions, such as httpd in this example. Classic Ruby. Given that go has popularized long args with a single hyphen (-name etc), it is easy to mistake -run as an option by itself. [1] https://github.com/ruby/ruby/blob/master/lib/un.rb#L323

> go has popularized long args, with a single hyphen (-name etc) Why did they do that? It took us 20 years to standardize on - for short and -- for long, with occasional finger rage on tar or find, and now this? What were they thinking?

> What were they thinking?

They were starting back from the 70s.

Also one more check for go being alt.history.java, this style is also the standard for Java tooling.

And Apple, I think.

Re: Big list of HTTP static server one-liners

#26

How many of these support the partial file loading? I know that Python don’t (I have been working on support for it). This would make SQLite example supported: https://news.ycombinator.com/item?id=27016630

The node one does, and there is a fork of the python one that does: https://github.com/danvk/RangeHTTPServer/

I know this because I have also been working on something using that magic sqlite-in-browser project :D

Re: Big list of HTTP static server one-liners

#27

Earlier quoted context omitted.

> go has popularized long args, with a single hyphen (-name etc) Why did they do that? It took us 20 years to standardize on - for short and -- for long, with occasional finger rage on tar or find, and now this? What were they thinking?

The XWindow system used -long -opts long before that.

...aaaand it's more than 20 years old, so yeah, that kinda agrees with the point that it took us a long time to stop doing that because it's confusing.

Re: Big list of HTTP static server one-liners

#28

Isn't python's server blocking? If you make two requests simultaneously, one of them will have to wait.

That’s correct. Well blocking is not much of an issue in and of itself but it’s blocking and single process and single threaded, so it can only serve one request at a time.

It’s not usually an issue for small stuff, but it does mean you can’t really use this snippet to serve big files for a lan, which is a bit of a surprise the first time you hit that limitation.

Re: Big list of HTTP static server one-liners

#30

The ruby one with the -run option is a bit nonintuitive in how it works. $ ruby -run -ehttpd . -p8000 The -r option requires un.rb[1] which is a file full of convenience functions, such as httpd in this example. Classic Ruby. Given that go has popularized long args with a single hyphen (-name etc), it is easy to mistake -run as an option by itself. [1] https://github.com/ruby/ruby/blob/master/lib/un.rb#L323

> go has popularized long args, with a single hyphen (-name etc) Why did they do that? It took us 20 years to standardize on - for short and -- for long, with occasional finger rage on tar or find, and now this? What were they thinking?

You can use -- or - as far as Go proper goes, doesn't matter in most cases. I think popular args libraries do that too, but there's a million of them, so some probably don't.
Post reply on HN