Skip to content

Enable Railway-friendly frontend/backend split via configurable API base URL#1

Merged
Dingge01 merged 1 commit into
mainfrom
copilot/check-frontend-page-on-deployment
Apr 19, 2026
Merged

Enable Railway-friendly frontend/backend split via configurable API base URL#1
Dingge01 merged 1 commit into
mainfrom
copilot/check-frontend-page-on-deployment

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 19, 2026

当前前端默认通过 hostname:8000 直连后端,这在 Railway 的公网部署模型下不稳定,无法保证通过 https://noteking-production.up.railway.app/ 直接访问前端并正确调用后端。此 PR 将前端后端地址解耦为环境变量驱动,并同步更新 Railway 双服务部署文档。

  • Frontend API routing(web)

    • 前端 API 基地址改为优先读取 NEXT_PUBLIC_API_URL
    • 对环境变量做尾部斜杠规范化,避免拼接出错。
    • 保留本地开发回退逻辑(未配置时仍可走 :8000)。
  • Railway deployment docs(docs/deploy-guide.md)

    • 明确推荐 Railway 拆分 api / web 两个服务。
    • 补充各服务职责与环境变量配置方式。
    • 明确将主访问域名绑定到 web 服务,后端由 NEXT_PUBLIC_API_URL 指向。
  • Environment variable reference(README.md)

    • 新增 NEXT_PUBLIC_API_URL 说明,标注 Railway 场景为关键配置项。
const resolveApiBase = () => {
  const envBase = process.env.NEXT_PUBLIC_API_URL?.trim();
  if (envBase) return envBase.replace(/\/+$/, "");
  if (typeof window !== "undefined") {
    return `${window.location.protocol}//${window.location.hostname}:8000`;
  }
  return "http://api:8000";
};

@Dingge01 Dingge01 marked this pull request as ready for review April 19, 2026 14:48
@Dingge01 Dingge01 merged commit aed845a into main Apr 19, 2026
1 check passed
Copilot stopped work on behalf of Dingge01 due to an error April 19, 2026 14:52
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.

2 participants