Serverless Next.js 9 on Netlify

Any more in-depth examples of this outside of the one previously posted?

Which one were you talking about that was previously posted, so we make sure not to give you the same one again? :slight_smile:

1 Like

Sorry!

https://github.com/mottox2-sandbox/next-on-netlify is the one I was referring to.

That example is the only one I am aware of. I see that Swyx posted that repo in this topic:

However, that repo was created by a third-party, not someone at Netlify. To clarify: Swyx is here at Netlify but the creator of the repo is not.

I am not aware of other examples of using Next.js 9 on Netlify. If you find out more about this, please feel free to add that information here.

Hey everyone,

Fellow NextJS- and Netlify-fan here! :heart:

I’ve been looking for a way to bring serverless NextJS to Netlify for a while. And I’m very happy to share that I’ve found a solution! :grin:

I’ve packed that solution up into a small npm package called next-on-netlify. It’s just a compatibility wrapper for hosting NextJS apps on Netlify. Check out this Medium article on getting started in 5 quick steps.

Basically, the package does three things:

  1. Copy each NextJS pages into either the public directory (if it uses .getInitialProps and does not need to be SSRed) OR the functions directory (if it uses .getInitialProps and does need to be SSRed)
  2. Create a Netlify function called nextRouter that is responsible for server-side rendering those pages that use .getInitialProps
  3. Set up a Netlify _redirects file and proxy all requests for SSR pages to the nextRouter Netlify function

You can check out a demo here: next-on.netlify.com/
And you can check out the main script of the package here: https://github.com/FinnWoelm/next-on-netlify/blob/master/next-on-netlify.js

Let me know what you think, whether you run into any issues, any ideas for improvements, etc… And if you end up building anything with next-on-netlify, I would love to hear about it, too :slight_smile:

3 Likes

Hi, @finn.woelm, welcome to our Netlify community site and wow! Wow and thank you!

This is an incredibly helpful contribution. Thank you for creating it and for sharing what you created here with the community.

It would be wonderful if people that experiment with and use this package would share their thoughts about it here as well. Please feel free to make comments about this below (and/or to create a new topic to discuss specific issues).

This is fantastic! Thanks again. :+1: