Live data from Hacker News

Big list of HTTP static server one-liners

gist.github.com

41–50 of 100 posts

Re: Big list of HTTP static server one-liners

#42
post #40

Weird to call these one liners, they're just invocation commands. By that logic, apache is a one-liner.

apache requires a config file. I guess you could put any relevant config into a single line and pipe that through somehow, but it would be a lot more than a single command to define a directory and a port to serve.

Re: Big list of HTTP static server one-liners

#43
post #40

Weird to call these one liners, they're just invocation commands. By that logic, apache is a one-liner.

Apache requires configuration. The point of those is that they're opening ad hoc an HTTP server without requiring any configuration.

Edit: Someone has posted an Apache example: https://gist.github.com/willurd/5720255#gistcomment-3050599

Re: Big list of HTTP static server one-liners

#44

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

Thank you! I like the monkey patch to enable binary range support: https://github.com/danvk/RangeHTTPServer/blob/master/RangeHT...

Re: Big list of HTTP static server one-liners

#46

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?

My hunch is that Rob Pike, Ken Thompson, Russ Cox and the other Bell Labs alumni behind Go disliked GNU getopt-style flags, like they dislike a lot of other GNU and BSD decisions that "contaminate" the original philosophy behind Unix.

This overall attitude has led to many design decisions in Go, which define the language for better or worse. Statically-linked executables, for instance, contributed more than anything else to Go's popularity as a CLI tool language. Of course, the Bell Labs crowd was already highly skeptical of dynamic linking. See Rob Pike's opinion here: http://harmful.cat-v.org/software/dynamic-linking/

I say it's a hunch, but I think Russ Cox's following comments pretty much demonstrate this attitude against GNUisms and BSDisms: https://github.com/golang/go/issues/2096#issuecomment-660578... https://news.ycombinator.com/item?id=9207316

On the other hand, Russ clearly goes on to say they designed the flags not based on Plan 9 (which only had short single-letter flags), but on Google's gflags library: https://github.com/golang/go/issues/2096#issuecomment-660578...

In short, it's probably both:

- Innate distrust of all things BSD/GNU meant that the original Go team didn't feel they have to honor the established tradition. Just like dynamic linking, they believed that if there is something that GNU does wrong, they don't need to follow it just for the sake of keeping compatibility.

- Positive experience using gflags convinced the team that the gflags approach (single-dash long flags) is the best one.

I personally think they were wrong here. As Russ Cox himself clearly stated in response to all requests for fixing go flags: there are many libraries out there who implement GNU-style flags. What happened in practice is that most Go developers voted with their feet and chose a third-party flag module (even Google's own Kubernetes is using spf13/cobra). In the end, the Go flags package just ended up causing more confusion and didn't solve any of the problems (perceived or real) with GNU flags.

Re: Big list of HTTP static server one-liners

#47
post #36

Only one mention of socat, nothing does ad-hoc nonsense that you probably would never use again like socat. > socat TCP4-LISTEN:50000,fork EXEC:/usr/bin/ifconfig > curl --http0.9 localhost:50000 Hmmm, does http v0.9 count?

Probably because the example you made doesn't look like a static file server, it seems to execute a specific unix command on incoming request only. The rest of the examples from the gist is proper static file servers.

I'd be interested in seeing if you can come up with a socat one-liner that works like a static file server. Would come in handy for many things, but I can't seem to figure out how to make it work.

Re: Big list of HTTP static server one-liners

#48

What's a good one that serves gzip assets if they exist? I'm looking for a way to serve a webpack prod build.

These are development servers, they are not meant for production builds (many don't handle concurrent requests, memory/performance is probably too poor as well).

Caddy works well and is easy to use and could replace most of these examples, not only for development but for production usage too.

Otherwise go for nginx/apache. Learn the config syntax once, get lifetime worth of value :)

Re: Big list of HTTP static server one-liners

#49
post #36

Only one mention of socat, nothing does ad-hoc nonsense that you probably would never use again like socat. > socat TCP4-LISTEN:50000,fork EXEC:/usr/bin/ifconfig > curl --http0.9 localhost:50000 Hmmm, does http v0.9 count?

Probably because the example you made doesn't look like a static file server, it seems to execute a specific unix command on incoming request only. The rest of the examples from the gist is proper static file servers. I'd be interested in seeing if you can come up with a socat one-liner that works like a static file server. Would come in handy for many things, but I can't seem to figure out how to make it work.

Many examples here in the comments and in the gist itself don't follow it to the letter either, it's easy enough to serve one file.

This one might work https://github.com/avleen/bashttpd

> socat TCP4-LISTEN:8080 EXEC:/usr/local/bin/bashttpd

Post reply on HN