News for hackers. Stuff that matters.
Re:Show HN: Nano-web, a low latency one binary webserver des... by qwerty456127 on Monday March 25, 2024 @11:01AM (#39817180)
By the way, is there a really minimal, really fast, reasonably secure, zero-cofig single-binary web server which would only support HTTP GET and just expose all the static content in a given directory over it?
Re:Show HN: Nano-web, a low latency one binary webserver des... by supriyo-biswas on Monday March 25, 2024 @11:10AM (#39817292)
"caddy file-server"[1] and sirv-cli[2] should have you covered, but in case you're looking for something more niche and less powerful, you could look at busybox httpd[3].

I wrote something similar long ago in < 400 lines of Go (with most of it being templates and mimetype information) that just supports GET, HEAD and gzip, in case you're interested[4].

[1] https://caddyserver.com/docs/quick-starts/static-files

[2] https://www.npmjs.com/package/sirv-cli

[3] https://openwrt.org/docs/guide-user/services/webserver/http....

[4] https://github.com/supriyo-biswas/gohttpd

Re:Show HN: Nano-web, a low latency one binary webserver des... by qwerty456127 on Monday March 25, 2024 @11:14AM (#39817343)
Thanks, I'll take a look. I also care about it being reasonably secure so I don't write it myself (I'm far from a pro in avoiding vulnerabilities) and also prefer to decrease the attack surface by giving up all non-essential features.

gzip is unnecessary because 99% of the traffic I would serve is going to be pre-compressed (like zip and jpeg files).

Re:Show HN: Nano-web, a low latency one binary webserver des... by ricardobeat on Monday March 25, 2024 @11:11AM (#39817301)
Caddy [1] is a single binary. It is not minimal, but the size difference is barely noticeable.

serve also comes to mind. If you have node installed, `npx serve .` does exactly that.

There are a few go projects that fit your description, none of them very popular, probably because they end up being a 100-line wrapper around http frameworks.

[1] https://caddyserver.com/

Re:Show HN: Nano-web, a low latency one binary webserver des... by busfahrer on Monday March 25, 2024 @01:55PM (#39819365)
Depending on the environment I'm in I either use `npx serve` or `python3 -m http.server` (aka `python2 -m SimpleHTTPServer`)
Re:Show HN: Nano-web, a low latency one binary webserver des... by rmbyrro on Monday March 25, 2024 @03:43PM (#39820502)
Python http server is not intended for public exposure. It's meant for local usage in testing / debugging contexts.
Re:Show HN: Nano-web, a low latency one binary webserver des... by egeozcan on Monday March 25, 2024 @03:33PM (#39820414)
Caddy is amazing for simple static hosting AND more, if one needs it. With sqlite, postgres, D3.js and FFmpeg, it's up there in my software love list.
Re:Show HN: Nano-web, a low latency one binary webserver des... by qwerty456127 on Wednesday March 27, 2024 @12:42AM (#39835763)
> It is not minimal, but the size difference is barely noticeable.

Minimality is not about size, it's about reducing the attack surface.

> There are a few go projects that fit your description, none of them very popular, probably because they end up being a 100-line wrapper around http frameworks.

Indeed. Everyone can write their own but dependencies will make its attack surface enormous and performance will probably be mediocre at best.

Re:Show HN: Nano-web, a low latency one binary webserver des... by beklein on Monday March 25, 2024 @11:28AM (#39817539)
I can recommend redbean[1], it's basically a webserver and your static files in a zip file that is executable on basically any computer. It's also super small, includes TLS and reasonably fast.

[1] https://redbean.dev

Re:Show HN: Nano-web, a low latency one binary webserver des... by eddd-ddde on Monday March 25, 2024 @03:21PM (#39820298)
TIL you can actually get a single binary to execute in multiple operating systems.

Redbean in general seems great and really interesting.

Re:Show HN: Nano-web, a low latency one binary webserver des... by kragen on Monday March 25, 2024 @11:30AM (#39817571)
you might want to write your own; i hacked httpdito together for this purpose one weekend. you won't find anything that beats it on 'really minimal' by more than 2 kibibytes :)

readme: http://canonical.org/~kragen/sw/dev3/httpdito-readme

source (single file): http://canonical.org/~kragen/sw/dev3/server.s

it might be reasonable to configure its port and mime types map on the command line instead of in the source, but at the moment it's arguably a bit too zero-configuration

it runs on linux, can handle about 20000 hits per second, has about 20 kilobytes of memory footprint when idle, and needs another 4 kilobytes per concurrently open connection (though the kernel needs several times that)

20000 hits per second is not really fast in the sense that other servers on the same hardware and kernel can handle more than twice that, but it can saturate a gigabit pipe if your files average 7 kilobytes or more

Re:Show HN: Nano-web, a low latency one binary webserver des... by rkeene2 on Monday March 25, 2024 @11:16AM (#39817367)
I wrote filed[0] for this. It is VERY fast in terms of low-latency (it doesn't even open the file its serving if it can help it) -- although it doesn't generate a dynamic directory listing, so it may not meet your needs if you want any dynamic content like that.

[0] https://filed.rkeene.org/

Re:Show HN: Nano-web, a low latency one binary webserver des... by cdaringe on Monday March 25, 2024 @11:56AM (#39817925)
actually readable C. kudos
Re:Show HN: Nano-web, a low latency one binary webserver des... by rkeene2 on Monday March 25, 2024 @02:08PM (#39819483)
Thanks, I've come a long way since my first C programs in the 90s, "sadly" lost to the sands of time. Earliest I can find is [0].

[0] https://rkeene.org/viewer/devel/vmi586/main.c.htm

Re:Show HN: Nano-web, a low latency one binary webserver des... by xprueg on Monday March 25, 2024 @03:00PM (#39820061)
Should "test/plain" be "text/plain" "in mime.types?
Re:Show HN: Nano-web, a low latency one binary webserver des... by rkeene2 on Monday March 25, 2024 @04:44PM (#39821073)
Yes, thank you, it is now fixed :-)
Re:Show HN: Nano-web, a low latency one binary webserver des... by Alifatisk on Monday March 25, 2024 @11:39AM (#39817699)
Yeah, Vercel created a tool for such case called serve. https://www.npmjs.com/package/serve
Re:Show HN: Nano-web, a low latency one binary webserver des... by antihero on Monday March 25, 2024 @11:54AM (#39817898)
This is that. Unless you mean having a directory listing, in which case, it is not.
Re:Show HN: Nano-web, a low latency one binary webserver des... by PhilippGille on Monday March 25, 2024 @01:04PM (#39818716)
I created this some years ago: https://github.com/philippgille/serve

It's written in Go, has zero third party dependencies, supports optional basic auth, and optional TLS cert generation (self signed) for local HTTPS.

Not updated in a while though.

And if you drop the requirement for minimalism I'd second the recommendation for Caddy instead.

Re:Show HN: Nano-web, a low latency one binary webserver des... by dclowd9901 on Monday March 25, 2024 @01:07PM (#39818757)
Not sure what single binary means but here’s my take.

https://github.com/dclowd9901/posse

Re:Show HN: Nano-web, a low latency one binary webserver des... by KomoD on Monday March 25, 2024 @01:24PM (#39818985)
Single binary meaning you only need a single binary to run it, nothing else. Yours is not single binary nor zero config
Re:Show HN: Nano-web, a low latency one binary webserver des... by dclowd9901 on Thursday March 28, 2024 @09:29AM (#39851141)
Helpful, thanks
Re:Show HN: Nano-web, a low latency one binary webserver des... by Borg3 on Monday March 25, 2024 @02:06PM (#39819470)
You want adhoc HTTP server or daemon? I wrote my adhoc HTTP server for serving files from my desktop right away. If interested, leave comment, I can make it public.
Re:Show HN: Nano-web, a low latency one binary webserver des... by adrianlv512 on Monday March 25, 2024 @02:13PM (#39819543)
Not sure if it meets all of your requirements, but what about using Crystal HTTP::Server[1] and building a fully statically linked[2] binary and deploying via a Docker scratch image[3] using a Multi-stage build[4].

Here's[5] an example I put together that I have running on fly.io[6]. I'm doing a redirect for root path, but it could easily be changed to serve up the contents of index.html.

I use a similar deployment for a small site I created[7] to generate UUIDs. Kemal[8] also looks like a good alternative.

----

Update:

Here's[9] an example also running on fly.io[10] using Kemal[8]

[1] https://crystal-lang.org/api/1.11.2/HTTP/Server.html

[2] https://crystal-lang.org/reference/1.11/guides/static_linkin...

[3] https://docs.docker.com/build/building/multi-stage/

[4] https://hub.docker.com/_/scratch/

[5] https://github.com/adrianlv512/minimal-server

[6] https://minimal-server.fly.dev

[7] https://uuid-generator.org/

[8] https://kemalcr.com/

[9] https://github.com/adrianlv512/minimal-server-kemal

[10] https://minimal-server-kemal.fly.dev

Re:Show HN: Nano-web, a low latency one binary webserver des... by dns_snek on Monday March 25, 2024 @04:53PM (#39821152)
I don't think anyone looking to just serve static files wants to touch a programming language, deal with any (additional) build steps, or run Docker. Especially the parent who expressed "minimal" as a requirement.
Re:Show HN: Nano-web, a low latency one binary webserver des... by adrianlv512 on Monday March 25, 2024 @07:14PM (#39822353)