Skip to content

Make public base path runtime-safe - #54

Merged
midagedev merged 1 commit into
mainfrom
public-base-path-runtime
May 13, 2026
Merged

Make public base path runtime-safe#54
midagedev merged 1 commit into
mainfrom
public-base-path-runtime

Conversation

@midagedev

Copy link
Copy Markdown
Owner

Summary

  • make the published frontend bundle runtime-prefix safe by using relative Vite asset paths
  • derive the browser public base path from the current URL for app links and API calls
  • always redirect hosted /checkout and /portal entrypoints into /app/... so runtime prefix detection is stable
  • extend web smoke to verify hosted checkout redirects under PUBLIC_BASE_PATH
  • clarify docs that GHCR images do not need per-prefix frontend rebuilds

Validation

  • go test ./... -count=1
  • npm run build
  • PUBLIC_BASE_PATH=/billtap BILLTAP_PUBLIC_BASE_URL=http://127.0.0.1:18080 BILLTAP_WEB_SMOKE_PORT=18080 npm run smoke:web
  • forbidden keyword scan over public code/docs/tests

Deployment note

PR #53 deployed a working server-side prefix layer, but the prebuilt GHCR image still needed this runtime-safe frontend adjustment so one published image can be mounted at /, /billtap, or another proxy path without rebuilding.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE

Summary

이 PR은 Billtap의 프론트엔드 번들을 런타임 시점의 public base path에 안전하게 동작하도록 개선합니다. GHCR에 게시된 단일 Docker 이미지가 /, /billtap, 또는 다른 프록시 경로에 마운트될 때 프론트엔드 자산을 다시 빌드할 필요 없이 동작하도록 합니다.

핵심 변경사항

1. Vite 빌드 설정 변경 (vite.config.ts)

  • base: appBasePathbase: "./" 변경
  • 빌드 시점의 절대 경로 대신 런타임 시점의 상대 경로를 사용하도록 변경
  • 정적 자산(JS, CSS, favicon)이 상대 경로로 로드되어 어느 경로에서든 동작

2. 런타임 base path 감지 (web/shared/basePath.ts)

  • 빌드 시점 환경변수(import.meta.env.BASE_URL) 제거
  • globalThis.location.pathname에서 실제 경로 추출하는 regex로 대체
  • /app/, /checkout/, /portal/ 경로에서 prefix를 안정적으로 감지

3. HTML favicon 경로 변경

4. 서버 리다이렉트 강화 (internal/server/server.go)

  • /checkout/portal 핸들러에서 정적 파일 직접 서빙 제거
  • 항상 /app/... 경로로 리다이렉트하도록 변경
  • 런타임 prefix 감지의 안정성 보장

5. 테스트 추가

  • server_test.go: 체크아웃 리다이렉트 동작 테스트 추가
  • smoke-web.mjs: PUBLIC_BASE_PATH 하에서 호스티드 리다이렉트 검증 추가

검증 관찰사항

  • ✅ Billing state: 변경 없음
  • ✅ Webhook reliability: 변경 없음
  • ✅ Safety: 결제 처리, 실제 카드 데이터, 시크릿 처리와 무관한 순수 배포 유연성 개선
  • ✅ Backwards compatibility: 기존 PUBLIC_BASE_PATH 설정 계속 지원
  • ✅ Test coverage: 새로운 동작에 대한 단위 테스트 및 웜 스모크 테스트 추가

결론

이 PR은 배포 유연성을 개선하는 인프라 변경입니다. 빌링 상태, 웹훅 신뢰성, 보안 경계에 영향을 주지 않으며, 테스트와 문서가 적절히 업데이트되었습니다. PR #53의 서버사이드 prefix 처리와 함께 완전한 runtime-prefix 지원을 제공합니다.

Reviewed by Z.ai GLM via Claude Code Action

@midagedev
midagedev merged commit 77b807a into main May 13, 2026
3 checks passed
@midagedev
midagedev deleted the public-base-path-runtime branch May 13, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant