Skip to content

Commit

Permalink
Merge pull request #3241 from owid/serve-img-local-env
Browse files Browse the repository at this point in the history
fix(dev): serve gdoc images on local dev
  • Loading branch information
ikesau authored Mar 19, 2024
2 parents 93a0abe + 22022bd commit 0add80f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions adminSiteServer/mockSiteRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { GdocPost } from "../db/model/Gdoc/GdocPost.js"
import { GdocDataInsight } from "../db/model/Gdoc/GdocDataInsight.js"
import * as db from "../db/db.js"
import { calculateDataInsightIndexPageCount } from "../db/model/Gdoc/gdocUtils.js"
import { DEFAULT_LOCAL_BAKE_DIR } from "../site/SiteConstants.js"

require("express-async-errors")

Expand Down Expand Up @@ -307,6 +308,13 @@ mockSiteRouter.use(
})
)

mockSiteRouter.use(
"/images/published",
express.static(path.join(DEFAULT_LOCAL_BAKE_DIR, "images/published"), {
fallthrough: false,
})
)

mockSiteRouter.use(
"/exports",
express.static(path.join(BAKED_SITE_DIR, "exports"))
Expand Down
3 changes: 2 additions & 1 deletion baker/buildLocalBake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { BakeStep, BakeStepConfig, bakeSteps, SiteBaker } from "./SiteBaker.js"
import fs from "fs-extra"
import { normalize } from "path"
import * as db from "../db/db.js"
import { DEFAULT_LOCAL_BAKE_DIR } from "../site/SiteConstants.js"

const bakeDomainToFolder = async (
baseUrl = "http://localhost:3000/",
dir = "localBake",
dir = DEFAULT_LOCAL_BAKE_DIR,
bakeSteps?: BakeStepConfig
) => {
dir = normalize(dir)
Expand Down
2 changes: 2 additions & 0 deletions site/SiteConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ const polyfillFeatures = [
export const POLYFILL_URL: string = `https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=${polyfillFeatures.join(
","
)}`

export const DEFAULT_LOCAL_BAKE_DIR = "localBake"

0 comments on commit 0add80f

Please sign in to comment.