Stackbit sites are built to be fully static by default. You can unlock Next.js server-side features like API routes and server-side rendering with a few quick changes.

Add Essential Next.js Build Plugin

Open package.json in the code editor and add the @netlify/plugin-nextjs package as a dev dependency. You can check the plugin repo for the latest tag.

{
  // ...
  "devDependencies": {
    "@stackbit/cli": "^0.1.25",
    "@netlify/plugin-nextjs": "4.1.1"
  }
}

This will prompt a restart of the SSG preview.

While the preview is rebooting, open netlify.toml and activate the plugin by adding the following code to the bottom of the file.

[[plugins]]
  package = "@netlify/plugin-nextjs"

Change Publish Directory

Also in netlify.toml, tell Netlify you'd like to publish the .next directory rather than out.

[build]
  command = "npm run build"
  publish = ".next"
  functions = ".netlify/functions"

Update Build Command

Although not strictly necessary, you can optimize your builds by removing && next export from the build script in package.json. The resulting script should just be next build.

{
  "scripts": {
    "dev": "next dev",
    "build": "next build"
    // ...
  }
}

Publish Changes

Though server features work in the SSG preview, they will not work on the live site until you publish changes.

Take care to consider other pending content or code changes when publishing.