Environment Variables
Configuration variables for Next.js and Drupal.
.env.local
# RequiredNEXT_PUBLIC_DRUPAL_BASE_URL=http://localhost:8080NEXT_IMAGE_DOMAIN=localhost
# Required for On-demand RevalidationDRUPAL_REVALIDATE_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 NextDrupal
client.
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 NextDrupal(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL)
On-demand Revalidation
Environment variables required for on-demand revalidation.
Name | Description |
---|---|
DRUPAL_REVALIDATE_SECRET | The secret for on-demand revalidation. Example: U2Y5bbkKJ08Ua8F |
app/api/revalidate/route.ts
async function handler(request: NextRequest) { const searchParams = request.nextUrl.searchParams const secret = searchParams.get("secret")
// Validate secret. if (secret !== process.env.DRUPAL_REVALIDATE_SECRET) { return new Response("Invalid secret.", { status: 401 }) }}
export { handler as GET, handler as POST }
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 NextDrupal(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 NextDrupal(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 NextDrupal(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, { frontPage: process.env.DRUPAL_FRONT_PAGE,})