1.1.2 • Published 7 months ago
next-revalidate-route v1.1.2
next-reavalidate-route
Tired of writing Next.js revalidate endpoint every time? Use next-reavalidate-route! It generates a Next.js route handler that you can use to revalidate paths and tags through query parameters. Optional allows you to protect it with Authorization header.
Setup
npm i next-revalidate-route
- Create a route
app/revalidate/route.ts
- Create the handler
import { nextRevalidateRoute } from 'next-revalidate-route'
// Send GET request to /revalidate?tags=one,two&paths=/blog/[slug],/route
// Protect with Authorization header
export async function GET(req: NextRequest) {
return nextRevalidateRoute(req, {
auth: 'your_secret',
trustLocalhost: true,
})
}
// Protect with custom auth callback
export async function GET(req: NextRequest) {
return nextRevalidateRoute(req, {
auth: async () => !!(await authorize()), // must return boolean
trustLocalhost: true,
})
}
Examples
curl -H "Authorization: your_secret" https://example.com/revalidate?tags=one,two,three&paths=/about,/blog/[slug],/route
fetch('https://example.com/revalidate?tags=one,two,three&paths=/about,/blog/[slug],/route', {
headers: {
Authorization: 'your_secret',
},
})