Skip to content

Commit

Permalink
cache image route
Browse files Browse the repository at this point in the history
  • Loading branch information
dekkerglen committed Oct 15, 2024
1 parent 6e44c1b commit c3a59da
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions routes/tools_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,14 @@ router.get('/cardimage/:id', async (req, res) => {
// if id is not a scryfall ID, error
const card = carddb.cardFromId(id);
if (card.error) {
res.setHeader('Cache-Control', 'public, max-age=604800'); // Cache for 1 month
return redirect(req, res, '/content/default_card.png');
}

res.setHeader('Cache-Control', 'public, max-age=604800'); // Cache for 1 month
return redirect(req, res, card.image_normal);
} catch {
res.setHeader('Cache-Control', 'public, max-age=604800'); // Cache for 1 year
return redirect(req, res, '/content/default_card.png');
}
});
Expand Down

0 comments on commit c3a59da

Please sign in to comment.