Settings

Theme

Show HN: I built a library to host your Next.js app statically on S3/CloudFront

github.com

2 points by zdenham 2 years ago · 0 comments · 1 min read

Reader

As the next.js server-less feature set has become more robust, I find myself reaching for the static site generation feature more often than not.

Static hosting is cheaper, and significantly reduces the underlying infrastructure overhead / risk of hosting your site. It also cuts the switching cost if you every need to change providers.

That being said, dynamic routes don’t work the way you would expect with the latest app router + SSG, and most static hosting providers (e.g. S3 + Cloudfront) don’t handle routing with next.js code splitting properly out of the box.

After running into these issues with a few projects, I bit the bullet and hacked together next-static-utils to make it simpler to port your next.js site to any static hosting provider, starting with S3 + cloudfront, which suited my use case.

It works by generating “fallback pages” for the dynamic routes as well as a cloudfront edge function to handle properly routing requests to the fallbacks and avoiding dreaded 404s.

I’m using it for an admin dashboard where SEO / SSR is not important, and we have a separate backend. Hope folks on HN find it useful too!

No comments yet.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection