fix(web): redact public host targets
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* Sentry Tunnel API Route
|
||||
* =======================
|
||||
*
|
||||
* 解決問題: 前端 Sentry DSN 使用內網 IP (192.168.0.110:9000) 會觸發
|
||||
* 解決問題: 前端 Sentry DSN 使用內網 origin 會觸發
|
||||
* 瀏覽器「存取區域網路上的其他裝置」權限對話框。
|
||||
*
|
||||
* 解決方案: 使用 Next.js API Route 作為 Tunnel,前端透過公網域名
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
// Sentry Self-Hosted 內網地址
|
||||
// 2026-04-22 ogt: 改為讀 env var,避免內網 IP 硬碼進 bundle。
|
||||
// K8s: awoooi-secrets → SENTRY_HOST;本機 dev fallback 維持原值不中斷。
|
||||
const SENTRY_HOST = process.env.SENTRY_HOST ?? 'http://192.168.0.110:9000';
|
||||
// Sentry Self-Hosted 目標只允許由 runtime env 明確注入;不可在 source 留私網 fallback。
|
||||
const SENTRY_HOST = process.env.SENTRY_HOST?.trim() ?? '';
|
||||
|
||||
// 允許的 Project IDs (防止濫用)
|
||||
const ALLOWED_PROJECT_IDS = new Set(['2', '3']); // awoooi-web: 2, awoooi-api: 3
|
||||
@@ -51,6 +49,14 @@ export async function POST(request: NextRequest) {
|
||||
);
|
||||
}
|
||||
|
||||
if (!SENTRY_HOST) {
|
||||
console.error('[Sentry Tunnel] Missing SENTRY_HOST');
|
||||
return NextResponse.json(
|
||||
{ error: 'Sentry tunnel target is not configured' },
|
||||
{ status: 503 }
|
||||
);
|
||||
}
|
||||
|
||||
// 轉發到 Sentry Server
|
||||
const response = await fetch(`${SENTRY_HOST}/api/${projectId}/envelope/`, {
|
||||
method: 'POST',
|
||||
@@ -83,6 +89,6 @@ export async function GET() {
|
||||
return NextResponse.json({
|
||||
status: 'ok',
|
||||
tunnel: '/api/sentry-tunnel',
|
||||
target: SENTRY_HOST,
|
||||
target_configured: Boolean(SENTRY_HOST),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user