Oops, fix production outfit SSR

That's what I get for not testing lol!
This commit is contained in:
Emi Matchu 2021-05-14 20:02:32 -07:00
parent 34ada18beb
commit 0fafeb92e1

View file

@ -20,6 +20,7 @@ const beeline = require("honeycomb-beeline")({
import escapeHtml from "escape-html"; import escapeHtml from "escape-html";
import fetch from "node-fetch"; import fetch from "node-fetch";
import { promises as fs } from "fs"; import { promises as fs } from "fs";
import * as path from "path";
import connectToDb from "../src/server/db"; import connectToDb from "../src/server/db";
import { normalizeRow } from "../src/server/util"; import { normalizeRow } from "../src/server/util";
@ -108,12 +109,19 @@ let cachedIndexPageHtml = null;
async function loadIndexPageHtml() { async function loadIndexPageHtml() {
if (cachedIndexPageHtml == null) { if (cachedIndexPageHtml == null) {
if (process.env.NODE_ENV === "development") { 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( const htmlFromDevServer = await fetch(
"http://localhost:3000/" "http://localhost:3000/"
).then((res) => res.text()); ).then((res) => res.text());
cachedIndexPageHtml = htmlFromDevServer; cachedIndexPageHtml = htmlFromDevServer;
} else { } 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; cachedIndexPageHtml = htmlFromFile;
} }
} }