fix: change tag to tags for revalidation
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import { env } from "@/env/server"
|
||||
import { revalidateTag } from 'next/cache'
|
||||
import { revalidateTag } from "next/cache"
|
||||
|
||||
import type { NextRequest } from 'next/server'
|
||||
import type { NextRequest } from "next/server"
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const secret = request.nextUrl.searchParams.get("secret") ?? ""
|
||||
const tag = request.nextUrl.searchParams.get("tag") ?? ""
|
||||
const tagsParam = request.nextUrl.searchParams.get("tags") ?? ""
|
||||
|
||||
if (secret !== env.REVALIDATE_SECRET) {
|
||||
return Response.json(
|
||||
{
|
||||
message: 'Invalid secret',
|
||||
message: "Invalid secret",
|
||||
now: Date.now(),
|
||||
revalidated: false,
|
||||
},
|
||||
@@ -21,10 +21,10 @@ export async function POST(request: NextRequest) {
|
||||
)
|
||||
}
|
||||
|
||||
if (!tag) {
|
||||
if (!tagsParam) {
|
||||
return Response.json(
|
||||
{
|
||||
message: 'Missing tag param',
|
||||
message: "Missing tags param",
|
||||
now: Date.now(),
|
||||
revalidated: false,
|
||||
},
|
||||
@@ -34,12 +34,31 @@ export async function POST(request: NextRequest) {
|
||||
)
|
||||
}
|
||||
|
||||
revalidateTag(tag)
|
||||
const tags = tagsParam.split(",")
|
||||
if (!tags.length) {
|
||||
return Response.json(
|
||||
{
|
||||
message: "No tags",
|
||||
now: Date.now(),
|
||||
revalidated: false,
|
||||
},
|
||||
{
|
||||
status: 400,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
tags.forEach((tag) => {
|
||||
revalidateTag(tag)
|
||||
})
|
||||
|
||||
return Response.json({ revalidated: true, now: Date.now() })
|
||||
} catch (error) {
|
||||
console.info("Failed to revalidate tag")
|
||||
console.info("Failed to revalidate tag(s)")
|
||||
console.error(error)
|
||||
return Response.json({ revalidated: false, now: Date.now() }, { status: 500 })
|
||||
return Response.json(
|
||||
{ revalidated: false, now: Date.now() },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user