Environment Variables

Configuration variables for Next.js and Drupal.


.env.local

# Required
NEXT_PUBLIC_DRUPAL_BASE_URL=http://localhost:8080
NEXT_IMAGE_DOMAIN=localhost
# Required for On-demand Revalidation
DRUPAL_REVALIDATE_SECRET=
# Authentication (Bearer)
DRUPAL_CLIENT_ID=
DRUPAL_CLIENT_SECRET=
# Authentication (Basic)
DRUPAL_USERNAME=
DRUPAL_PASSWORD=
# Optional
DRUPAL_SITE_ID=
DRUPAL_FRONT_PAGE=

Required

These environment variables are required for initializing a new NextDrupal client.

NameDescription
NEXT_PUBLIC_DRUPAL_BASE_URLThe base url for your Drupal site. Example: https://drupal.org
NEXT_IMAGE_DOMAINThe 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.

NameDescription
DRUPAL_REVALIDATE_SECRETThe 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)

NameDescription
DRUPAL_CLIENT_IDThe OAuth client id. Example: a53b1d17-6b23-478d-8649-9aee63974c80
DRUPAL_CLIENT_SECRETThe 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)

NameDescription
DRUPAL_USERNAMEThe Drupal username. Example: admin
DRUPAL_PASSWORDThe 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.

NameDescription
DRUPAL_SITE_IDThe site id of the Next.js site on Drupal. Example: marketing_site. See the Filter by site guide for usage example.
DRUPAL_FRONT_PAGEThe 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,
})