Skip to content

Commit db42421

Browse files
committed
fix(frontend): auto-redirect root path to locale based on browser language
- Update proxy.ts matcher to capture all paths including / - Remove basePath placeholder from Dockerfile (was breaking redirects) - Extend entrypoint placeholder replacement coverage
1 parent ade48dc commit db42421

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

frontend/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ COPY . .
1919
# Disable telemetry during build
2020
ENV NEXT_TELEMETRY_DISABLED=1
2121

22-
# Build with placeholders - will be replaced at runtime by entrypoint script
23-
ENV NEXT_PUBLIC_BASE_PATH="/__NEXT_BASEPATH_PLACEHOLDER__"
22+
# Build without basePath (root deployment)
23+
# For subpath deployment, rebuild with NEXT_PUBLIC_BASE_PATH set
24+
ENV NEXT_PUBLIC_BASE_PATH=""
2425
ENV NEXT_PUBLIC_API_URL="__NEXT_API_URL_PLACEHOLDER__"
2526
ENV NEXT_PUBLIC_WS_URL="__NEXT_WS_URL_PLACEHOLDER__"
2627

frontend/docker-entrypoint.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,21 @@ if [ -n "$BASE_PATH" ]; then
1414
# Escaped version first (for regex patterns in JSON)
1515
find /app/.next/static -type f -name "*.json" -exec sed -i "s|${BASEPATH_PLACEHOLDER_ESCAPED}|${ESCAPED_BASE_PATH}|g" {} + 2>/dev/null || true
1616
find /app/.next/static -type f \( -name "*.js" -o -name "*.json" \) -exec sed -i "s|${BASEPATH_PLACEHOLDER}|${BASE_PATH}|g" {} + 2>/dev/null || true
17-
find /app/.next/server -type f \( -name "*.html" -o -name "*.rsc" \) -exec sed -i "s|${BASEPATH_PLACEHOLDER}|${BASE_PATH}|g" {} + 2>/dev/null || true
17+
find /app/.next/server -type f \( -name "*.html" -o -name "*.rsc" -o -name "*.meta" -o -name "*.body" \) -exec sed -i "s|${BASEPATH_PLACEHOLDER}|${BASE_PATH}|g" {} + 2>/dev/null || true
1818
find /app/.next/server -type f -name "*client-reference-manifest.js" -exec sed -i "s|${BASEPATH_PLACEHOLDER}|${BASE_PATH}|g" {} + 2>/dev/null || true
19+
# Also handle prerender manifests and action manifests
20+
find /app/.next -type f -name "*.json" -exec sed -i "s|${BASEPATH_PLACEHOLDER}|${BASE_PATH}|g" {} + 2>/dev/null || true
1921
else
2022
echo "No BASE_PATH set, running at root path"
2123
sed -i "s|${BASEPATH_PLACEHOLDER}||g" /app/server.js 2>/dev/null || true
2224
sed -i "s|${BASEPATH_PLACEHOLDER}||g" /app/.next/routes-manifest.json 2>/dev/null || true
2325
# Escaped version first (for regex patterns in JSON)
2426
find /app/.next/static -type f -name "*.json" -exec sed -i "s|${BASEPATH_PLACEHOLDER_ESCAPED}||g" {} + 2>/dev/null || true
2527
find /app/.next/static -type f \( -name "*.js" -o -name "*.json" \) -exec sed -i "s|${BASEPATH_PLACEHOLDER}||g" {} + 2>/dev/null || true
26-
find /app/.next/server -type f \( -name "*.html" -o -name "*.rsc" \) -exec sed -i "s|${BASEPATH_PLACEHOLDER}||g" {} + 2>/dev/null || true
28+
find /app/.next/server -type f \( -name "*.html" -o -name "*.rsc" -o -name "*.meta" -o -name "*.body" \) -exec sed -i "s|${BASEPATH_PLACEHOLDER}||g" {} + 2>/dev/null || true
2729
find /app/.next/server -type f -name "*client-reference-manifest.js" -exec sed -i "s|${BASEPATH_PLACEHOLDER}||g" {} + 2>/dev/null || true
30+
# Also handle prerender manifests and action manifests
31+
find /app/.next -type f -name "*.json" -exec sed -i "s|${BASEPATH_PLACEHOLDER}||g" {} + 2>/dev/null || true
2832
fi
2933

3034
API_URL="${NEXT_PUBLIC_API_URL:-http://localhost:8000}"

frontend/proxy.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { routing } from './i18n/routing';
44
export default createMiddleware(routing);
55

66
export const config = {
7-
// Match only internationalized pathnames
8-
matcher: ['/', '/(fr|en)/:path*'],
7+
matcher: [
8+
// Match all pathnames except:
9+
// - API routes starting with /api
10+
// - Next.js internals (_next)
11+
// - Static files with extensions
12+
'/((?!api|_next|.*\\..*).*)'
13+
],
914
};

0 commit comments

Comments
 (0)