Skip to content

Commit bb667df

Browse files
committed
fix: custom domain basePath configuration
1 parent 595f3e8 commit bb667df

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ jobs:
4949

5050
- name: Build Next.js app
5151
run: pnpm run build
52+
env:
53+
# Set to empty string for custom domain (e.g., rektsafe.com)
54+
# Remove or comment out this line if using username.github.io/repo-name
55+
BASE_PATH: ""
5256

5357
- name: Upload artifact
5458
uses: actions/upload-pages-artifact@v3

next.config.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
import type { NextConfig } from "next";
22

33
// For GitHub Pages deployment:
4-
// If using a custom domain, set basePath: ""
5-
// If using username.github.io/repo-name, set basePath: "/repo-name"
4+
// If using a custom domain, set BASE_PATH="" or leave empty
5+
// If using username.github.io/repo-name, BASE_PATH defaults to "/repo-name"
66
const isGithubActions = process.env.GITHUB_ACTIONS === "true";
77
const repoName = process.env.GITHUB_REPOSITORY?.split("/")[1] || "";
88

9+
// Allow manual override via BASE_PATH env var
10+
// For custom domain (e.g., rektsafe.com): set BASE_PATH=""
11+
// For project page (e.g., user.github.io/repo): leave unset or set BASE_PATH="/repo"
12+
const basePath =
13+
process.env.BASE_PATH !== undefined
14+
? process.env.BASE_PATH
15+
: isGithubActions && repoName
16+
? `/${repoName}`
17+
: "";
18+
919
const nextConfig: NextConfig = {
1020
output: "export",
1121
distDir: "dist",
12-
basePath: isGithubActions && repoName ? `/${repoName}` : "",
13-
assetPrefix: isGithubActions && repoName ? `/${repoName}` : "",
22+
basePath: basePath,
23+
assetPrefix: basePath,
1424
images: {
1525
unoptimized: true,
1626
},

0 commit comments

Comments
 (0)