Live data from Hacker News

Show HN: Nano-web – a low latency one binary webserver designed for serving SPAs

github.com

1–10 of 119 posts

Show HN: Nano-web – a low latency one binary webserver designed for serving SPAs

#1
I'd found that whilst there's a lot of good options out there for webservers, I was looking for something that is a single deployable binary for usage with containers or unikernels and solves some of the problems that you get with other setups like nginx.

It uses a single compiled binary, it's going to have extremely low latency on account of caching all files in memory at runtime, and also the fun feature and really useful that's good for SPAs (e.g. Vite) or things like Astro is that you can inject configuration variables into it at runtime and access them from within your frontend code, so you don't have to rebuild any images for different environments as part of your CI.

Whilst I'm sure this problem has been solved time and time again, I could never get a solution to be quite right.

Also, serving things like Astro from S3 gets to be tricky because CloudFront doesn't support index pages in subdirectories so the routing breaks. This fixes this.

Use it or don't, I think it's a cool little project and it's been a while since I worked on and released something :)

Show HN: Nano-web – a low latency one binary webserver designed for serving SPAs
github.com

Re: Show HN: Nano-web – a low latency one binary webserver designed for serving SPAs

#2
I like the idea!

Have you seen redbean, which is a universal binary and serves static files from a zipfile? How does this compare to that?

Honestly, I think that the current Web can easily use libp2p from IPFS and serve files from any browser peer to peer, with relays on the internet.

I think the Web lacks two major things:

1) Address resolution only uses federated DNS and you need extensions to use, say, self-sovereign Web3 domains which can’t be stolen

2) There is NO WAY to load files by their content hash like onion links in Tor. If there was, we’d have a much more secure Web.

Re: Show HN: Nano-web – a low latency one binary webserver designed for serving SPAs

#4
Can you elaborate "CloudFront doesn't support index pages in subdirectories" and how does it not work?

I'm not much into them these days but if I remember correctly in the 4-5 years prior, they just works! In-fact, CloudFront was easier to serve static web assets than serving directly from S3.

Or have I misunderstood what you meant?

Re: Show HN: Nano-web – a low latency one binary webserver designed for serving SPAs

#6

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?

"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 [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 designed for serving SPAs

#7

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?

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 designed for serving SPAs

#8
> SPA mode to service 404s as index (200) to support client side routing.

Be careful: SPAs can handle 404s client-side.

All you need to do is continue to return the 404 result code and include the same exact content that you normally do.

Then your SPA recognizes that the route isn't set up and displays the error page.

Re: Show HN: Nano-web – a low latency one binary webserver designed for serving SPAs

#9

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?

"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 [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/goh…

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 designed for serving SPAs

#10
Neat idea! We did a blog post around just using nginx for something similar. Which is to say NGINX serving SPA. https://medium.com/disney-streaming/api-driven-spa-with-ngin...

There is even a sample template repos. https://medium.com/disney-streaming/api-driven-spa-with-ngin...

Looking forward to diving into nano-web

Post reply on HN