3 ms·
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
by qwerty456127 3y ago
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?
- supriyo-biswas 3y ago"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 https://caddyserver.com/docs/quick-starts/static-files [2] https://www.npmjs.com/package/sirv-cli https://www.npmjs.com/package/sirv-cli [3] https://openwrt.org/docs/guide-user/services/webserver/http.httpd https://openwrt.org/docs/guide-user/services/webserver/http.... [4] https://github.com/supriyo-biswas/gohttpd https://github.com/supriyo-biswas/gohttpd
- qwerty456127 3y agoThanks, 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).
- ricardobeat 3y agoCaddy [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/ https://caddyserver.com/
- busfahrer 3y agoDepending on the environment I'm in I either use `npx serve` or `python3 -m http.server` (aka `python2 -m SimpleHTTPServer`)
- rmbyrro 3y agoPython http server is not intended for public exposure. It's meant for local usage in testing / debugging contexts.
- egeozcan 3y agoCaddy 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.
- qwerty456127 3y ago> 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.
- rkeene2 3y agoI 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/ https://filed.rkeene.org/
- cdaringe 3y agoactually readable C. kudos
- rkeene2 3y agoThanks, 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 https://rkeene.org/viewer/devel/vmi586/main.c.htm
- xprueg 3y agoShould "test/plain" be "text/plain" "in mime.types?
- rkeene2 3y agoYes, thank you, it is now fixed :-)
- beklein 3y agoI 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 https://redbean.dev
- eddd-ddde 3y agoTIL you can actually get a single binary to execute in multiple operating systems. Redbean in general seems great and really interesting.
- kragen 3y agoyou 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 http://canonical.org/~kragen/sw/dev3/httpdito-readme source (single file): http://canonical.org/~kragen/sw/dev3/server.s 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
- Alifatisk 3y agoYeah, Vercel created a tool for such case called serve. https://www.npmjs.com/package/serve https://www.npmjs.com/package/serve
- antihero 3y agoThis is that. Unless you mean having a directory listing, in which case, it is not.
- PhilippGille 3y agoI created this some years ago: https://github.com/philippgille/serve 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.
- dclowd9901 3y agoNot sure what single binary means but here’s my take. https://github.com/dclowd9901/posse https://github.com/dclowd9901/posse
- KomoD 3y agoSingle binary meaning you only need a single binary to run it, nothing else. Yours is not single binary nor zero config
- dclowd9901 3y agoHelpful, thanks
- Borg3 3y agoYou 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.
- adrianlv512 3y agoNot 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 https://crystal-lang.org/api/1.11.2/HTTP/Server.html [2] https://crystal-lang.org/reference/1.11/guides/static_linking.html#fully-static-linking https://crystal-lang.org/reference/1.11/guides/static_linkin... [3] https://docs.docker.com/build/building/multi-stage/ https://docs.docker.com/build/building/multi-stage/ [4] https://hub.docker.com/_/scratch/ https://hub.docker.com/_/scratch/ [5] https://github.com/adrianlv512/minimal-server https://github.com/adrianlv512/minimal-server [6] https://minimal-server.fly.dev https://minimal-server.fly.dev [7] https://uuid-generator.org/ https://uuid-generator.org/ [8] https://kemalcr.com/ https://kemalcr.com/ [9] https://github.com/adrianlv512/minimal-server-kemal https://github.com/adrianlv512/minimal-server-kemal [10] https://minimal-server-kemal.fly.dev https://minimal-server-kemal.fly.dev
- dns_snek 3y agoI 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.
- adrianlv512 3y agoNot sure this is true regarding Docker, e.g.: https://github.com/radiosilence/nano-web?tab=readme-ov-file#docker-quick-start https://github.com/radiosilence/nano-web?tab=readme-ov-file#... https://github.com/lipanski/docker-static-website https://github.com/lipanski/docker-static-website https://github.com/PierreZ/goStatic https://github.com/PierreZ/goStatic