From a0121f09ea827cf2947845628431a1e3b60ffd86 Mon Sep 17 00:00:00 2001 From: Matchu Date: Fri, 14 May 2021 20:47:15 -0700 Subject: [PATCH] Use current host for outfit share tags This will help test preview pages and such! --- api/outfitPageSSR.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/api/outfitPageSSR.js b/api/outfitPageSSR.js index 2f626f1..9eb8068 100644 --- a/api/outfitPageSSR.js +++ b/api/outfitPageSSR.js @@ -27,6 +27,12 @@ import fetch from "node-fetch"; import connectToDb from "../src/server/db"; import { normalizeRow } from "../src/server/util"; +const DTI_HOST = process.env.VERCEL_URL + ? `https://${process.env.VERCEL_URL}` + : process.env.NODE_ENV === "development" + ? "http://localhost:3000" + : "https://impress-2020.openneo.net"; + async function handle(req, res) { // Load index.html as our initial page content. If this fails, it probably // means something is misconfigured in a big way; we don't have a great way @@ -76,10 +82,8 @@ 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( + const outfitUrl = `${DTI_HOST}/outfits/${encodeURIComponent(outfit.id)}`; + const imageUrl = `${DTI_HOST}/api/outfitImage?size=600&id=${encodeURIComponent( outfit.id )}&updatedAt=${updatedAtTimestamp}`; const metaTags = ` @@ -112,12 +116,7 @@ async function loadIndexPageHtml() { if (cachedIndexPageHtml == null) { // Request the same built copy of index.html that we're already serving at // our homepage. - const homepageUrl = process.env.VERCEL_URL - ? `https://${process.env.VERCEL_URL}/` - : process.env.NODE_ENV === "development" - ? "http://localhost:3000/" - : "https://impress-2020.openneo.net/"; - const liveIndexPageHtml = await fetch(homepageUrl).then((res) => + const liveIndexPageHtml = await fetch(`${DTI_HOST}/`).then((res) => res.text() ); cachedIndexPageHtml = liveIndexPageHtml;