Live data from Hacker News

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

github.com

51–60 of 119 posts

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

#51
post #41

> SPA_MODE when set to 1 404 request will return /public/index.html as a 200. oof, as someone who frequently has to run DAST tools, returning a 200 for something that should be a 404 is the bane of my existence. The tool will try to request sensitive files by trying something as simple as fetching hxxps://example.com/../../../etc/passwd. If you return a "200 OK", it will flag as a security issue, even if the resultin…

But if it's an SPA, how else would you handle this case? How is the webserver supposed to know in advance which URLs the SPA is able to handle?

I typically keep all my SPA routes/route names in a single JSON, and then reference those from the App, instead of repeating the routes everywhere. I can then pass those to the server to let it know what the SPA can handle.

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

#52

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?

Not sure what single binary means but here’s my take. https://github.com/dclowd9901/posse

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

#53
post #51
post #41

Earlier quoted context omitted.

But if it's an SPA, how else would you handle this case? How is the webserver supposed to know in advance which URLs the SPA is able to handle?

I typically keep all my SPA routes/route names in a single JSON, and then reference those from the App, instead of repeating the routes everywhere. I can then pass those to the server to let it know what the SPA can handle.

This is an opinionated approach that is out of scope really I think. Though if it works for you, awesome!

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

#54

> SPA_MODE when set to 1 404 request will return /public/index.html as a 200. oof, as someone who frequently has to run DAST tools, returning a 200 for something that should be a 404 is the bane of my existence. The tool will try to request sensitive files by trying something as simple as fetching hxxps://example.com/../../../etc/passwd. If you return a "200 OK", it will flag as a security issue, even if the resultin…

But how could this possibly be correct if the route is correct within the context of the client side code which uses history API to route, which the server knows nothing about? Else you’re going back to the days of hash routes which nobody likes.

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

#55
post #37

Earlier quoted context omitted.

I just figured any savings where savings can be made is a good thing, especially if there are zero downsides, plus it means very low CPU usage as it's literally just pulling from RAM without any CPU usage. It also precaches gzipped and brotli'd versions of sensible files so that it can accept-encoding for a variety of browsers.

Couldn't the extra memory copies end up being an actual downside? I.e. the sort of thing that inspired sendfile(2) usage in some servers?

I’m not so sure, if you’re serving massive files this is not perhaps the option you want. If your SPA is so big you can’t handle a container that has its app code and assets in RAM perhaps it’s also too large.

I see it as a pragmatic trade off between speed and RAM. Even free tier EC2 instance should have enough RAM to handle pretty much any SPA even if the text content is duplicated (compressed) especially seeing as with a unikernel you have no RAM used up by Linux processes.

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

#56
post #23

Considering the latency between the user web browser and the server, does the “extremely low latency on account of caching all files in memory” really matter? The files should already be cached by the OS and using sendfile lets the OS copy the file directly to the network.

> serving things like Astro from S3 Given that point, I got the impression that the comparison was against loading resources from S3. The difference between that and serving from memory (even between that and serving from uncached traditional hard-drive) is going to be significant. EDIT: cursory research suggests S3 latency ( https://stackoverflow.com/a/861539/114292 , being the most recent reference that turned up)…

Yeah I see this as a viable alternative to serving from S3 (I mean, which is still a great option I recommend provided you aren’t exposing S3 directly and set up S3 properly locked down) but the original niche was having an SPA web interface that runs on a k8s cluster as part of wider service where you want a tiny minimal and fast image that can be configurable when the pod is spun up. I just then expanded it to be a bit not of a general solution to have fun with it.

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

#57
post #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-sovere…

Federation’s a non-starter when most devices people use are battery powered and don’t like to hold connections open when idle. Like, it works, but it won’t work well enough unless most devices are just going through gateways, which largely defeats the point.

What about all those desktop computers on 24/7 in the world?

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

#58
post #22
post #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.

Yep, returning the wrong HTTP status code is going to confuse a lot of search engines, chat app link previews, and other automated consumers of your SPA, even if you subsequently display the correct error page.

>returning the wrong HTTP status code is going to confuse a lot of search engines

How is the search engine going to find a page that doesn't exist, isn't in a sitemap, isn't linked to in any nav anchors, in order to index it?

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

#59
post #37

Earlier quoted context omitted.

Couldn't the extra memory copies end up being an actual downside? I.e. the sort of thing that inspired sendfile(2) usage in some servers?

I’m not so sure, if you’re serving massive files this is not perhaps the option you want. If your SPA is so big you can’t handle a container that has its app code and assets in RAM perhaps it’s also too large. I see it as a pragmatic trade off between speed and RAM. Even free tier EC2 instance should have enough RAM to handle pretty much any SPA even if the text content is duplicated (compressed) especially seeing as…

I think the argument is the same for files that fit in memory. This sort of thing is fairly well-trodden (if unsettled, to mix up the metaphors) ground, for yet another take there's varnish and Poul-Henning Kamp's strident writings about it.

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

#60

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/

Depending on the environment I'm in I either use `npx serve` or `python3 -m http.server` (aka `python2 -m SimpleHTTPServer`)
Post reply on HN