From 0fafeb92e1ba6ddeeaacba458f582c8ec918693e Mon Sep 17 00:00:00 2001 From: Matchu Date: Fri, 14 May 2021 20:02:32 -0700 Subject: [PATCH] Oops, fix production outfit SSR That's what I get for not testing lol! --- api/outfitPageSSR.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/api/outfitPageSSR.js b/api/outfitPageSSR.js index 20d10db..11d3864 100644 --- a/api/outfitPageSSR.js +++ b/api/outfitPageSSR.js @@ -20,6 +20,7 @@ const beeline = require("honeycomb-beeline")({ import escapeHtml from "escape-html"; import fetch from "node-fetch"; import { promises as fs } from "fs"; +import * as path from "path"; import connectToDb from "../src/server/db"; import { normalizeRow } from "../src/server/util"; @@ -108,12 +109,19 @@ let cachedIndexPageHtml = null; async function loadIndexPageHtml() { if (cachedIndexPageHtml == null) { if (process.env.NODE_ENV === "development") { + // In development, request a built version of index.html from the dev + // server, by visiting `/`. const htmlFromDevServer = await fetch( "http://localhost:3000/" ).then((res) => res.text()); cachedIndexPageHtml = htmlFromDevServer; } else { - const htmlFromFile = await fs.readFile("../build/index.html", "utf8"); + // In production, read the build version of index.html from the local + // `build` directory. + const htmlFromFile = await fs.readFile( + path.join(__dirname, "../build/index.html"), + "utf8" + ); cachedIndexPageHtml = htmlFromFile; } }