Skip to content

Commit

Permalink
Bugfix revalidate show artwork (#163)
Browse files Browse the repository at this point in the history
* remove allowed origins for testing

* allow all origins temporarily for testing

* add preflight options handling

* set to allow all headers

* change allowed origin to be from contentfukl
  • Loading branch information
antiantivirus authored Jan 16, 2025
1 parent 351c5c6 commit 72f6586
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pages/api/cron/artwork-email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default async function handler(

for (const show of shows) {
let showEmailed = false;
let artwork = show.showArtwork.url + "?fm=jpg";
let artwork = show.artwork.url + "?fm=jpg";

for (const artist of show.artistsCollection.items) {
if (artist.email && !emailedArtists.has(artist.email)) {
Expand Down
17 changes: 13 additions & 4 deletions pages/api/revalidate/show-artwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@ export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const origin = req.headers.origin;
const allowedOrigin = process.env.NEXT_PUBLIC_SITE_URL;
// const origin = req.headers.origin;
// const allowedOrigin = process.env.NEXT_PUBLIC_SITE_URL;

if (origin !== allowedOrigin) {
return res.status(403).json({ error: "Forbidden" });
// if (origin !== allowedOrigin) {
// return res.status(403).json({ error: "Forbidden" });
// }

res.setHeader("Access-Control-Allow-Origin", "https://app.contentful.com");
res.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "*");

// Handle preflight requests
if (req.method === "OPTIONS") {
return res.status(200).end();
}

if (req.method === "POST") {
Expand Down
2 changes: 1 addition & 1 deletion types/shared.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export interface ShowInterface {
};
content: Content;
status?: string;
showArtwork?: CoverImage;
artwork?: CoverImage;
}

export type PastShowSchema = {
Expand Down

0 comments on commit 72f6586

Please sign in to comment.