Environment Variables
Configuration variables for Next.js and Drupal.
.env.local
# RequiredNEXT_PUBLIC_DRUPAL_BASE_URL=http://localhost:8080NEXT_IMAGE_DOMAIN=localhost
# Required for Preview ModeDRUPAL_PREVIEW_SECRET=
# Authentication (Bearer)DRUPAL_CLIENT_ID=DRUPAL_CLIENT_SECRET=
# Authentication (Basic)DRUPAL_USERNAME=DRUPAL_PASSWORD=
# OptionalDRUPAL_SITE_ID=DRUPAL_FRONT_PAGE=
Required
These environment variables are required for initializing a new DrupalClient
.
Name | Description |
---|---|
NEXT_PUBLIC_DRUPAL_BASE_URL | The base url for your Drupal site. Example: https://drupal.org |
NEXT_IMAGE_DOMAIN | The domain name for next/image. Example: drupal.org |
const drupal = new DrupalClient(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL)
Preview Mode
Environment variables required for preview mode.
Name | Description |
---|---|
DRUPAL_PREVIEW_SECRET | The secret for preview mode. Example: 6SZy9xkdtR |
const drupal = new DrupalClient(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, { previewSecret: process.env.DRUPAL_PREVIEW_SECRET,})
Authentication (Bearer)
Name | Description |
---|---|
DRUPAL_CLIENT_ID | The OAuth client id. Example: a53b1d17-6b23-478d-8649-9aee63974c80 |
DRUPAL_CLIENT_SECRET | The OAuth client secret. Example: 3#9h$2DU#8qKb6& |
const drupal = new DrupalClient(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, { auth: { clientId: process.env.DRUPAL_CLIENT_ID, clientSecret: process.env.DRUPAL_CLIENT_SECRET, },})
Authentication (Basic)
Name | Description |
---|---|
DRUPAL_USERNAME | The Drupal username. Example: admin |
DRUPAL_PASSWORD | The Drupal password. Example: password |
const drupal = new DrupalClient(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, { auth: { username: process.env.DRUPAL_USERNAME, password: process.env.DRUPAL_PASSWORD, },})
Optional
These environment variables are optional and not required as of next-drupal 1.4.0
.
Name | Description |
---|---|
DRUPAL_SITE_ID | The site id of the Next.js site on Drupal. Example: marketing_site . See the Filter by site guide for usage example. |
DRUPAL_FRONT_PAGE | The path to the front page: Example: /front |
DRUPAL_SITE_ID
// Fetch all articles with DRUPAL_SITE_ID in field_sites.const nodes = await drupal.getResourceCollection<DrupalNode[]>( "node--article", { params: { filter: { "field_sites.meta.drupal_internal__target_id": process.env.DRUPAL_SITE_ID, }, }, })
DRUPAL_FRONT_PAGE
const drupal = new DrupalClient(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, { frontPage: process.env.DRUPAL_FRONT_PAGE,})