Create pretty route for outfit images

This is mostly for decoupling's sake: I want pretty outfit URLs that aren't dependent on the `/api/outfitImage` path structure, so that we can serve them as ~permanent pretty URLs that don't actually indicate where or how the image is stored.
This commit is contained in:
Emi Matchu 2021-05-20 20:35:41 -07:00
parent ae82a6236f
commit 0eec503b91
2 changed files with 13 additions and 7 deletions

View file

@ -76,12 +76,14 @@ async function handle(req, res) {
const updatedAtTimestamp = Math.floor(
new Date(outfit.updatedAt).getTime() / 1000
);
const outfitUrl = `https://impress-2020.openneo.net/outfits/${encodeURIComponent(
outfit.id
)}`;
const imageUrl = `https://impress-2020.openneo.net/api/outfitImage?size=600&id=${encodeURIComponent(
outfit.id
)}&updatedAt=${updatedAtTimestamp}`;
const outfitUrl =
`https://impress-2020.openneo.net/outfits` +
`/${encodeURIComponent(outfit.id)}`;
const imageUrl =
`https://impress-2020.openneo.net/outfits` +
`/${encodeURIComponent(outfit.id)}` +
`/v/${encodeURIComponent(updatedAtTimestamp)}` +
`/600.png`;
const metaTags = `
<meta property="og:title" content="${escapeHtml(outfit.name)}">
<meta property="og:type" content="website">

View file

@ -1,7 +1,11 @@
{
"routes": [
{
"src": "/outfits/(?<id>[^/]+)/v/(?<updatedAt>[^/]+)/(?<size>150|300|600).png",
"dest": "/api/outfitImage.js?size=$size&id=$id&updatedAt=$updatedAt"
},
{ "src": "/outfits/new(\\?|$)", "dest": "/index.html" },
{ "src": "/outfits/(?<id>[^/]*)", "dest": "/api/outfitPageSSR.js?id=$id" },
{ "src": "/outfits/(?<id>[^/]+)", "dest": "/api/outfitPageSSR.js?id=$id" },
{
"handle": "filesystem"
},