Upgrade Guide
Guide for upgrading your site to use DrupalClient.
The DrupalClient is an optional feature. If you're running a site using next-drupal 1.2 or below, you can safely upgrade your site without any breaking changes.
- Upgrade to the latest version
yarn add next-drupal@latest- Create a new
DrupalClientinlib/drupal.ts
lib/drupal.ts
import { DrupalClient } from "next-drupal"
export const drupal = new DrupalClient(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, { frontPage: "/home", previewSecret: process.env.DRUPAL_PREVIEW_SECRET, auth: { clientId: process.env.DRUPAL_CLIENT_ID, clientSecret: process.env.DRUPAL_CLIENT_SECRET, },})- Update helpers to use the
drupalclient.
+ import { drupal } from "lib/drupal"
- await getPathsFromContext()+ await drupal.getStaticPathsFromContext()
- await translatePathFromContext()+ await drupal.translatePathFromContext()
- await getResourceFromContext()+ await drupal.getResourceFromContext()- Replace
pages/api/preview.tswith the following:
- import { DrupalPreview } from "next-drupal"-- export default DrupalPreview()
+ import { drupal } from "lib/drupal"++ export default async function (request, response) {+ return await drupal.preview(request, response)+ }On the Drupal site, visit
/admin/people/permissions/anonymousand assign the Issue subrequests permission to the Anonymous user role:
We do this because during the build phase, most of the requests for pages are anonymous requests. By assigning this permission, you can significantly decrease your site's build time.
If you would rather keep requests authenticated, you can use thewithAuthoptions.Done. You are now ready to run your site using the new
DrupalClient.
If you see any bugs during the upgrade, feel free to create an issue on GitHub.
