1.1.2 • Published 2 years ago

next-revalidate-route v1.1.2

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

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

  1. npm i next-revalidate-route
  2. Create a route app/revalidate/route.ts
  3. 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',
  },
})
1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago