The new way (next-on-pages) builds to a Next.JS server that runs on Pages Functions, so that you can
The new way (next-on-pages) builds to a Next.JS server that runs on Pages Functions, so that you can use everything normally from Next.JS and get server-side rendering, Next.JS redirects, etc.
10 Replies
Pages Functions are similar to Workers, if you've used them, meaning they're only "on" when a request is coming in. So you're not always paying for hosting either.
so I first host my project on pages, then head to pages functions?
yeah, I've read a little bit about them
what I didn't understand is how is a pages function deployed
since my nextjs project will be on pages first, right?
You have two options:
1. Use static Next.JS on Pages, which is free for unlimited requests and traffic, but requires your site to export statically and doesn't allow using Next.JS redirects. You upload normally and specify your build command as
npm run export
(I think?)
2. Use next-on-pages, which is what that template you saw before is using. It will automatically build and deploy your site to a Function, no setup required aside from uploading to Pages. It also allows you to use Next.JS server-side rendering and redirects.
If you want to go with method 2, just upload your site as normal and use the Next.JS template that you saw.Interesting.
so my Next.JS rewrites will work as normal?
If you use next-on-pages they should, yes.
I see.
What about the default build directory in the template?
I leave it as is?
Yup, that template should be accurate.
Cool. I'll try this out in a bit
Sounds good - feel free to post here if you run into troubles 🙂
Sure! Thanks for the help till now
Seems like I missed something
Fixed it