-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor image url function (#189)
* feat: refactor image url * style(event-card): add back filter background * feat: revalidate API use POST
- Loading branch information
Showing
5 changed files
with
28 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,28 @@ | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
const simpleToken = process.env.XATA_API_KEY?.slice(0, 6); | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
const { secret, pathname } = req.query; | ||
// Check for secret to confirm this is a valid request | ||
if ( | ||
typeof process.env.XATA_API_KEY !== "string" || | ||
typeof secret !== "string" || | ||
typeof pathname !== "string" | ||
) { | ||
return res.status(401).json({ message: "Invalid token or params." }); | ||
const auth = req.headers.authorization; | ||
|
||
if (auth !== simpleToken) { | ||
return res.status(401).json({ message: "Invalid token." }); | ||
} | ||
const payload = req.body; | ||
|
||
const simpleToken = process.env.XATA_API_KEY.slice(0, 6); | ||
const { pathname } = payload; | ||
|
||
if (secret !== simpleToken) { | ||
return res.status(401).json({ message: "Invalid token" }); | ||
if (typeof pathname !== "string") { | ||
return res.status(401).json({ message: "Invalid path." }); | ||
} | ||
|
||
try { | ||
// this should be the actual path not a rewritten path | ||
// e.g. for "/blog/[slug]" this should be "/blog/post-1" | ||
await res.revalidate(pathname); | ||
return res.json({ revalidated: true }); | ||
return res.json({ revalidated: true, revalidatedPath: pathname }); | ||
} catch (err) { | ||
// If there was an error, Next.js will continue | ||
// to show the last successfully generated page | ||
return res.status(500).send("Error revalidating"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters