From a130dd191b9a6264ec24beb64e04037fbf527973 Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Sat, 4 Apr 2026 12:24:39 +0700 Subject: [PATCH] fix: make basePath configurable via NEXT_PUBLIC_BASE_PATH env var MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enables platform-agnostic deployment — GitHub Pages sets the env var in CI, while Vercel/Netlify/local dev default to root path. --- web/.github/workflows/deploy.yml | 2 ++ web/lib/champion-data.js | 3 ++- web/next.config.mjs | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/web/.github/workflows/deploy.yml b/web/.github/workflows/deploy.yml index 829680c..a33460b 100644 --- a/web/.github/workflows/deploy.yml +++ b/web/.github/workflows/deploy.yml @@ -28,6 +28,8 @@ jobs: - run: npm ci - run: npm run build + env: + NEXT_PUBLIC_BASE_PATH: /loldle - uses: actions/upload-pages-artifact@v3 with: diff --git a/web/lib/champion-data.js b/web/lib/champion-data.js index 11bb9b4..a524bb8 100644 --- a/web/lib/champion-data.js +++ b/web/lib/champion-data.js @@ -9,7 +9,8 @@ export async function loadChampions() { if (loadPromise) return loadPromise; loadPromise = (async () => { - const response = await fetch(`/loldle/champions.json`); + const basePath = process.env.NEXT_PUBLIC_BASE_PATH || ""; + const response = await fetch(`${basePath}/champions.json`); if (!response.ok) { loadPromise = null; throw new Error(`Failed to load champions: ${response.status}`); diff --git a/web/next.config.mjs b/web/next.config.mjs index 38e3208..5e38cca 100644 --- a/web/next.config.mjs +++ b/web/next.config.mjs @@ -1,7 +1,7 @@ /** @type {import('next').NextConfig} */ const nextConfig = { output: "export", - basePath: "/loldle", + basePath: process.env.NEXT_PUBLIC_BASE_PATH || "", images: { unoptimized: true, },