Live data from Hacker News

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

github.com

101–110 of 119 posts

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

#101

If this is the nano version then let me share the pico alternatives with you: * BusyBox httpd [1] * thttpd [2] * Lwan Web Server [3] * gatling [4] I built and maintain a super tiny Docker image (~158KB) for serving static files [5]. My current implementation is based on Busybox httpd and scratch but I also tried out thttpd in the past, which worked well but came with a high memory footprint in some cases. thttpd was…

OP says of nano-web:

> you can inject configuration variables into it at runtime and access them from within your frontend code

Is there a way to do that with BusyBox httpd or the others?

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

#102

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 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 f…

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

#103

Earlier quoted context omitted.

Indeed, for a cost-effective approach with a static host, why not generate placeholder HTML files for all valid routes at compile time? Alternatively, using Astro or a similar tool would be a wise choice :)

This isn’t really feasible, think about how dynamic routes can be? Can you generate a route for every ID of a thing?

I have actually seen this approach for SSG. You define a function to get all IDs, then the framework renders all of the pages using those.

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

#104
post #79

Earlier quoted context omitted.

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

I'm not sure what is 'opinionated' about this approach. It seems like a pretty standard and reasonable way of correctly serving an SPA in a way that doesn't violate web standards.

So this would mean you would have to dynamically generate your webservers configuration at the build time of your SPA?

And then how are you handling routes with params inside? In your SPA they would probably be configured like

  /user/:id/post/:post
Now you would have to translate that to something the webserver config understands, probably wildcard / glob pattern / regex stuff and splice that into the web server config?

I mean it's possible, sure, but that's a lot of overhead and room for error just to deploy a simple SPA, it definitely is an opinionated approach.

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

#105
post #79

Earlier quoted context omitted.

I'm not sure what is 'opinionated' about this approach. It seems like a pretty standard and reasonable way of correctly serving an SPA in a way that doesn't violate web standards.

So this would mean you would have to dynamically generate your webservers configuration at the build time of your SPA? And then how are you handling routes with params inside? In your SPA they would probably be configured like /user/:id/post/:post Now you would have to translate that to something the webserver config understands, probably wildcard / glob pattern / regex stuff and splice that into the web server confi…

I don’t know. Computers are pretty damn good at transforming text. It sounds pretty simple really, it’s probably less than a week to build something rock solid.

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

#106
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.

easy enough to solve with Prerender. when using it I include some head tags to allow the Prerender server to send codes like 404 or 301. It's worked well for SEO compatibility, I even wrote a small React router project to handle this situation automatically (as well as other TSEO considerations like trailing vs non-trailing slashes).

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

#107

Earlier quoted context omitted.

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 f…

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.

Not sure this is true regarding Docker, e.g.:

https://github.com/radiosilence/nano-web?tab=readme-ov-file#...

https://github.com/lipanski/docker-static-website

https://github.com/PierreZ/goStatic

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

#108
post #83
post #58

Earlier quoted context omitted.

>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?

> 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? If links are never going to be used, there is no point in doing the effort of client side routing. If links are going to used, the server needs to respond with the correct status or you break the assumptions upon which the tools people use to access the web are based.

The article is about serving SPAs. In SPAs the "pages" are not really pages, they are program state. Just because you think /whatever shouldn't go to the homepage doesn't mean your way is the best way for an SPA to work. Maybe I'd rather display the current sale instead of a generic "404" error. Nothing wrong with that. If you're scraping my site or something, then too bad for you. The SPA server is under no obligation to serve any page with any specific response code so long as it is valid HTTP.

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

#109
post #51

Earlier quoted context omitted.

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!

I'd say not handling 404's correctly and simply returning a 200 OK is pretty opinionated, too.

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

#110
post #83

Earlier quoted context omitted.

> 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? If links are never going to be used, there is no point in doing the effort of client side routing. If links are going to used, the server needs to respond with the correct status or you break the assumptions upon which the tools people use to access the web are based.

The article is about serving SPAs. In SPAs the "pages" are not really pages, they are program state. Just because you think /whatever shouldn't go to the homepage doesn't mean your way is the best way for an SPA to work. Maybe I'd rather display the current sale instead of a generic "404" error. Nothing wrong with that. If you're scraping my site or something, then too bad for you. The SPA server is under no obligati…

> Just because you think /whatever shouldn't go to the homepage doesn't mean your way is the best way for an SPA to work. Maybe I'd rather display the current sale instead of a generic "404" error. Nothing wrong with that. I

Return a non-200 response doesn't mean you can't return a page. You can indeed display the current sale in the content returned with a 404 response and most sites do. A SPA absolutely can return tue full index.html content for every end point, but it shouldn't lie with it's status codes in the process.

> The SPA server is under no obligation to serve any page with any specific response code so long as it is valid HTTP.

You are also under no obligation to close your html tags or accessibility guidelines. However, ignoring specs like this can break things for your users in ways you can't always predict, especially for more marginal use cases.

If you're gonna to write a SPA, please, I beg to you, actually take the time to do it properly and release tools that enable that. Otherwise you are directly contributing to making the internet worse.

Post reply on HN