Add Drupal headless stack with Next.js frontend
- Add Next.js frontend service (nextjs) with Dockerfile and source - Update docker-compose.yml: image names, Drupal 11.3.3, nextjs service - Add docker-compose.override.yml.disabled for dev hot-reload - Add install-headless-modules.sh for OAuth/JSON:API module setup - Add README.md with full setup and configuration guide - Update nginx/Dockerfile and nginx.conf.template for cms. subdomain - Update drupal/Dockerfile PHP-FPM build args - Gitignore **/.vscode/ to prevent IDE workspace files from being tracked
This commit is contained in:
parent
71a8dac389
commit
f8b8f53d54
85 changed files with 7802 additions and 17 deletions
6
drupal/nextjs/app/api/disable-draft/route.ts
Normal file
6
drupal/nextjs/app/api/disable-draft/route.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import { disableDraftMode } from "next-drupal/draft"
|
||||
import type { NextRequest } from "next/server"
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
return disableDraftMode()
|
||||
}
|
||||
7
drupal/nextjs/app/api/draft/route.ts
Normal file
7
drupal/nextjs/app/api/draft/route.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { drupal } from "@/lib/drupal"
|
||||
import { enableDraftMode } from "next-drupal/draft"
|
||||
import type { NextRequest } from "next/server"
|
||||
|
||||
export async function GET(request: NextRequest): Promise<Response | never> {
|
||||
return enableDraftMode(request, drupal)
|
||||
}
|
||||
9
drupal/nextjs/app/api/preview/route.ts
Normal file
9
drupal/nextjs/app/api/preview/route.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { enableDraftMode } from "next-drupal/draft"
|
||||
import { drupal } from "@/lib/drupal"
|
||||
import { NextRequest } from "next/server"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
return enableDraftMode(request, drupal)
|
||||
}
|
||||
35
drupal/nextjs/app/api/revalidate/route.ts
Normal file
35
drupal/nextjs/app/api/revalidate/route.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { revalidatePath } from "next/cache"
|
||||
import { NextRequest } from "next/server"
|
||||
|
||||
async function handler(request: NextRequest) {
|
||||
const searchParams = request.nextUrl.searchParams
|
||||
const secret = searchParams.get("secret")
|
||||
const path = searchParams.get("path")
|
||||
|
||||
// Validate the revalidation secret.
|
||||
if (secret !== process.env.DRUPAL_REVALIDATE_SECRET) {
|
||||
return new Response("Invalid secret.", { status: 401 })
|
||||
}
|
||||
|
||||
if (!path) {
|
||||
return new Response("Missing path.", { status: 400 })
|
||||
}
|
||||
|
||||
try {
|
||||
revalidatePath(path)
|
||||
return new Response(
|
||||
JSON.stringify({ revalidated: true, now: Date.now() }),
|
||||
{
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
}
|
||||
)
|
||||
} catch (error) {
|
||||
return new Response(
|
||||
JSON.stringify({ message: "Error revalidating.", error }),
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export { handler as GET, handler as POST }
|
||||
Loading…
Add table
Add a link
Reference in a new issue