This is a starter template for Next.js, extended to deploy with Begin that includes server side rendering.
Deploy your own clone of this app to Begin!
npm installnpm run devNavigate to localhost:3000. You should see your app running.
- Quickstart - basics on working locally, project structure, deploying, and accessing your Begin app
- Creating new routes - basics on expanding the capabilities of your app
Head to docs.begin.com to learn more!
The following steps can be used to deploy most Next apps to Begin.com.
-
Install dependencies to wrap Next server
npm i express serverless-http
-
Add
app.arcmanifest file to the root folder#app.arc @app next-SSR @http /* method get src begin -
Add a handler to server the Next App to the
beginfolder.//index.js let next = require("next"); //the following are added to satisfy next required dependencies during Begin hydration let _react = require("react") let _react_dom = require("react-dom") let express= require("express") let serverless = require('serverless-http'); let app = next({ dev:false }); let handle = app.getRequestHandler(); let server= express() server.get("*", (req, res) => { return handle(req, res); }); module.exports.handler = serverless(server)
-
Add a build script to
package.jsonto run on Begin."scripts": { "build": "NODE_ENV=production next build && cp -r .next begin/.next " }
-
Add build output folder to
.gitignore#.gitignore /begin/.next