/** * 客户端配置测试页面 * 用于验证Nginx代理和客户端ID检测是否正常工作 */ import { json, type LoaderFunctionArgs } from "@remix-run/node"; import { useLoaderData } from "@remix-run/react"; import { getApiConfig } from "~/config/api-config"; import { detectClientFromRequest, getRequestDebugInfo } from "~/utils/client-detection"; /** * 服务器端loader函数 - 获取配置和调试信息 */ export async function loader({ request }: LoaderFunctionArgs) { // 获取客户端配置 const config = getApiConfig(request); // 获取客户端检测信息 const detectedClientId = detectClientFromRequest(request); // 获取调试信息 const debugInfo = getRequestDebugInfo(request); // 获取当前URL信息 const url = new URL(request.url); return json({ config, detectedClientId, debugInfo, serverInfo: { url: url.href, host: url.host, port: url.port, pathname: url.pathname }, timestamp: new Date().toISOString() }); } /** * 客户端配置测试页面组件 */ export default function ClientConfigTest() { const data = useLoaderData(); // 浏览器端检测客户端ID const browserClientId = typeof window !== 'undefined' ? (() => { const port = window.location.port; const portToClient: Record = { '5174': 'client-a', '5175': 'client-b', '5176': 'client-c', '5177': 'client-d' }; return port && portToClient[port] ? portToClient[port] : 'unknown'; })() : 'server-side'; const browserPort = typeof window !== 'undefined' ? window.location.port : 'server-side'; return (

🧪 客户端配置测试页面

{/* 基本信息 */}

📍 访问信息

当前URL: {data.serverInfo.url}
主机: {data.serverInfo.host}
端口: {data.serverInfo.port || '默认端口'}
路径: {data.serverInfo.pathname}
浏览器端口: {browserPort}

🎯 客户端检测

服务器端检测: {data.detectedClientId}
浏览器端检测: {browserClientId}
{/* Nginx请求头信息 */}

🔍 Nginx请求头信息

X-Client-ID: {data.debugInfo.clientId || '未检测到'}
X-Original-Port: {data.debugInfo.originalPort || '未检测到'}
X-Forwarded-Port: {data.debugInfo.forwardedPort || '未设置'}
X-Real-IP: {data.debugInfo.realIp || '未设置'}
{/* 当前配置信息 */}

⚙️ 当前API配置

Base URL: {data.config.baseUrl}
Upload URL: {data.config.uploadUrl}
Document URL: {data.config.documentUrl}
OAuth Server: {data.config.oauth.serverUrl}
OAuth Redirect: {data.config.oauth.redirectUri}
OAuth Client ID: {data.config.oauth.clientId.substring(0, 20)}...
{/* 状态检查 */}

✅ 状态检查

{data.debugInfo.clientId ? '✅ Nginx X-Client-ID 传递正常' : '❌ Nginx X-Client-ID 未传递'}
{data.detectedClientId !== 'main' ? '✅ 服务器端客户端检测成功' : '⚠️ 服务器端使用默认配置'}
{browserClientId !== 'unknown' ? '✅ 浏览器端客户端检测成功' : '⚠️ 浏览器端使用默认配置'}
{data.config.baseUrl.includes(data.detectedClientId.replace('client-', '517')) ? '✅ 配置匹配正确' : '⚠️ 配置可能不匹配'}
{/* 调试信息 */}

🔧 完整调试信息

点击查看详细信息
                {JSON.stringify({
                  serverData: data,
                  browserInfo: {
                    clientId: browserClientId,
                    port: browserPort,
                    userAgent: typeof window !== 'undefined' ? navigator.userAgent : 'server-side'
                  }
                }, null, 2)}
              
{/* 测试链接 */}

🔗 其他客户端测试链接

{[ { port: '5174', client: 'client-a', name: '客户端A' }, { port: '5175', client: 'client-b', name: '客户端B' }, { port: '5176', client: 'client-c', name: '客户端C' }, { port: '5177', client: 'client-d', name: '客户端D' } ].map(({ port, client, name }) => ( {name}
:{port}
))}
最后更新: {data.timestamp}
); }