From a3bde7a5448da4d4b0aa77937aee9457e5e3f245 Mon Sep 17 00:00:00 2001 From: "Tony L. He" Date: Sat, 23 May 2026 02:48:20 -0400 Subject: [PATCH] feat: configurable backend base URL for local dev - config.jsx: route API URLs through NEXT_PUBLIC_API_BASE_URL with production fallback - .gitignore: ignore .env*.local - file-download.js: use same-origin download when srcUrl points to current host - mbs.jsx: correct Further Mathematics label Co-Authored-By: Claude Opus 4.7 (1M context) --- .gitignore | 3 +++ src/components/mbs.jsx | 2 +- src/config.jsx | 37 ++++++++++++++++------------------ src/utilities/file-download.js | 5 ++++- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 36e47b6..f1209e8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,8 @@ yarn.lock node_modules react-scratch +# Local env files +.env*.local + # Generated sitemaps public/sitemap*.xml diff --git a/src/components/mbs.jsx b/src/components/mbs.jsx index 773f37c..1dcf908 100644 --- a/src/components/mbs.jsx +++ b/src/components/mbs.jsx @@ -63,7 +63,7 @@ export default function MBS({
{ - toggleYearChoose("Mathematics (9231)") + toggleYearChoose("Mathematics Further (9231)") }}>

Further Mathematics

diff --git a/src/config.jsx b/src/config.jsx index e2b9d1f..cd04a3b 100644 --- a/src/config.jsx +++ b/src/config.jsx @@ -1,38 +1,35 @@ +const API_BASE_URL = + process.env.NEXT_PUBLIC_API_BASE_URL || "https://node.snapaper.com" + +const api = (path) => `${API_BASE_URL}${path}` + export default { apiUrl: { cates: { - alevel: "https://node.snapaper.com/api/cates/ppca/as-and-a-level/", - igcse: "https://node.snapaper.com/api/cates/ppca/igcse/", - // alevel: "https://node.snapaper.com/api/cates/a-levels/", - // igcse: "https://node.snapaper.com/api/cates/cambridge-IGCSE/", - // alevel: "https://node.snapaper.com/api/cates/ppco/A-Level/", - // igcse: "https://node.snapaper.com/api/cates/ppco/IGCSE/", + alevel: api("/api/cates/ppca/as-and-a-level/"), + igcse: api("/api/cates/ppca/igcse/"), }, papers: { xyz: { - alevel: "https://node.snapaper.com/api/papers/xyz/A%20Levels/", - igcse: "https://node.snapaper.com/api/papers/xyz/IGCSE/", + alevel: api("/api/papers/xyz/A%20Levels/"), + igcse: api("/api/papers/xyz/IGCSE/"), }, com: { - alevel: "https://node.snapaper.com/api/papers/com/a-levels/", - igcse: "https://node.snapaper.com/api/papers/com/cambridge-IGCSE/", + alevel: api("/api/papers/com/a-levels/"), + igcse: api("/api/papers/com/cambridge-IGCSE/"), }, ppco: { - alevel: "https://node.snapaper.com/api/papers/ppco/A-Level/", - igcse: "https://node.snapaper.com/api/papers/ppco/IGCSE/", + alevel: api("/api/papers/ppco/A-Level/"), + igcse: api("/api/papers/ppco/IGCSE/"), }, ppca: { - alevel: "https://node.snapaper.com/api/papers/ppca/as-and-a-level/", - igcse: "https://node.snapaper.com/api/papers/ppca/igcse/", + alevel: api("/api/papers/ppca/as-and-a-level/"), + igcse: api("/api/papers/ppca/igcse/"), }, }, years: { - alevel: "https://node.snapaper.com/api/years/ppca/as-and-a-level/", - igcse: "https://node.snapaper.com/api/years/ppca/igcse/", - // alevel: "https://node.snapaper.com/api/years/a-levels/", - // igcse: "https://node.snapaper.com/api/years/cambridge-IGCSE/", - // alevel: "https://node.snapaper.com/api/years/ppco/A-Level/", - // igcse: "https://node.snapaper.com/api/years/ppco/IGCSE/", + alevel: api("/api/years/ppca/as-and-a-level/"), + igcse: api("/api/years/ppca/igcse/"), }, }, } diff --git a/src/utilities/file-download.js b/src/utilities/file-download.js index e85e3aa..a503b20 100644 --- a/src/utilities/file-download.js +++ b/src/utilities/file-download.js @@ -1,5 +1,8 @@ export const downloadFile = (srcUrl) => { - const link = `https://files.snapaper.com/download?filename=${srcUrl}` + let link = `https://files.snapaper.com/download?filename=${srcUrl}` + if (srcUrl.includes(window.location.hostname)) { + link = `${srcUrl}?download=1` + } const iframe = document.createElement("iframe") iframe.setAttribute("id", new Date().getTime()) iframe.setAttribute("sandbox", "allow-downloads allow-scripts")