Skip to content

fix: External Apps proxy strips pathPrefix causing Bad Gateway for basePath-configured apps #376

@Kewton

Description

@Kewton

概要

External Apps のプロキシルートハンドラが pathPrefix を除去してupstreamに転送しているため、basePath を設定したアプリケーションに接続できず Bad Gateway エラーが発生する。

現象

  • http://localhost:3000/proxy/localllmtest/ にアクセスすると {"error":"Bad Gateway","message":"Unable to connect to upstream server"} が返る
  • http://localhost:3012/proxy/localllmtest/ に直接アクセスすると正常に表示される

原因

src/lib/proxy/handler.tsbuildUpstreamUrl() が pathPrefix を除去してupstreamに転送している。

// 現在の実装(handler.ts:39-43)
export function buildUpstreamUrl(app: ExternalApp, path: string): string {
  return `http://${app.targetHost}:${app.targetPort}${path}`;
}

プロキシルートハンドラ(src/app/proxy/[...path]/route.ts:30-31)が pathPrefix を除去:

const [pathPrefix, ...rest] = pathSegments;
const path = '/' + rest.join('/');  // pathPrefix が含まれない

これにより:

ブラウザ:  GET /proxy/localllmtest/page
  ↓ pathPrefix除去
upstream:  GET http://localhost:3012/page  ← 404(basePath設定済みアプリでは存在しないパス)

期待動作

設計書(Issue #42)ではアプリ側に basePath: '/proxy/{pathPrefix}' の設定を要求しているため、プロキシは pathPrefix を保持してupstreamに転送すべき。

ブラウザ:  GET /proxy/localllmtest/page
  ↓ pathPrefix保持
upstream:  GET http://localhost:3012/proxy/localllmtest/page  ← 200

修正対象

src/lib/proxy/handler.ts

  • buildUpstreamUrl()/proxy/{pathPrefix} を含むパスをupstreamに転送するよう修正

src/app/proxy/[...path]/route.ts

  • handleProxy() で pathPrefix を含むパスを proxyHttp() / proxyWebSocket() に渡すよう修正

影響範囲

  • External Apps 機能を利用している全アプリに影響
  • basePath 未設定のアプリ(ルート / で動作するアプリ)は動作が変わるため注意が必要

受入条件

  • http://localhost:3000/proxy/{pathPrefix}/ 経由でbasePath設定済みアプリにアクセスできる
  • ヘルスチェックが正常に動作する
  • 既存のテストが通る

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions