From 0eec503b9112a500e92dc42a9eb0102f4d2a5b59 Mon Sep 17 00:00:00 2001 From: Matchu Date: Thu, 20 May 2021 20:35:41 -0700 Subject: [PATCH] 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. --- api/outfitPageSSR.js | 14 ++++++++------ vercel.json | 6 +++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/api/outfitPageSSR.js b/api/outfitPageSSR.js index 2f626f1..69e5d9e 100644 --- a/api/outfitPageSSR.js +++ b/api/outfitPageSSR.js @@ -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 = ` diff --git a/vercel.json b/vercel.json index 1858cf7..9e1bff0 100644 --- a/vercel.json +++ b/vercel.json @@ -1,7 +1,11 @@ { "routes": [ + { + "src": "/outfits/(?[^/]+)/v/(?[^/]+)/(?150|300|600).png", + "dest": "/api/outfitImage.js?size=$size&id=$id&updatedAt=$updatedAt" + }, { "src": "/outfits/new(\\?|$)", "dest": "/index.html" }, - { "src": "/outfits/(?[^/]*)", "dest": "/api/outfitPageSSR.js?id=$id" }, + { "src": "/outfits/(?[^/]+)", "dest": "/api/outfitPageSSR.js?id=$id" }, { "handle": "filesystem" },