添加管理员登陆,添加nginx反向代理配置,
This commit is contained in:
+170
-25
@@ -30,31 +30,82 @@ interface ApiConfig {
|
||||
// 端口特定配置映射
|
||||
// 根据不同端口提供不同的API配置
|
||||
const portConfigs: Record<string, Partial<ApiConfig>> = {
|
||||
|
||||
// 测试主要服务实例
|
||||
'5173': {
|
||||
baseUrl: 'http://172.16.0.55:8008',
|
||||
documentUrl: 'http://172.16.0.55:8008/docauditai/',
|
||||
uploadUrl: 'http://172.16.0.55:8008/admin/documents'
|
||||
},
|
||||
// 测试客户端实例
|
||||
'5174': {
|
||||
baseUrl: 'http://172.16.0.55:5174',
|
||||
documentUrl: 'http://172.16.0.55:5174/docauditai/',
|
||||
uploadUrl: 'http://172.16.0.55:5174/admin/documents'
|
||||
},
|
||||
// 测试客户端实例
|
||||
'5175': {
|
||||
baseUrl: 'http://172.16.0.55:5175',
|
||||
documentUrl: 'http://172.16.0.55:5175/docauditai/',
|
||||
uploadUrl: 'http://172.16.0.55:5175/admin/documents'
|
||||
},
|
||||
// 测试客户端实例
|
||||
'5176': {
|
||||
baseUrl: 'http://172.16.0.55:5176',
|
||||
documentUrl: 'http://172.16.0.55:5176/docauditai/',
|
||||
uploadUrl: 'http://172.16.0.55:5176/admin/documents'
|
||||
},
|
||||
// 测试客户端实例
|
||||
'5177': {
|
||||
baseUrl: 'http://172.16.0.55:5177',
|
||||
documentUrl: 'http://172.16.0.55:5177/docauditai/',
|
||||
uploadUrl: 'http://172.16.0.55:5177/admin/documents'
|
||||
},
|
||||
// 测试客户端实例
|
||||
'5178': {
|
||||
baseUrl: 'http://172.16.0.55:8008',
|
||||
documentUrl: 'http://172.16.0.55:8008/docauditai/',
|
||||
uploadUrl: 'http://172.16.0.55:8008/admin/documents'
|
||||
},
|
||||
|
||||
|
||||
|
||||
// 主要
|
||||
'51703': {
|
||||
baseUrl: 'http://172.16.0.55:51703',
|
||||
documentUrl: 'http://172.16.0.55:51703/docauditai/',
|
||||
uploadUrl: 'http://172.16.0.55:51703/admin/documents'
|
||||
},
|
||||
|
||||
// 潮州
|
||||
'51704': {
|
||||
baseUrl: 'http://172.16.0.55:51704',
|
||||
documentUrl: 'http://172.16.0.55:51704/docauditai/',
|
||||
uploadUrl: 'http://172.16.0.55:51704/admin/documents'
|
||||
},
|
||||
|
||||
// 揭阳
|
||||
'51705': {
|
||||
baseUrl: 'http://172.16.0.55:51705',
|
||||
documentUrl: 'http://172.16.0.55:51705/docauditai/',
|
||||
uploadUrl: 'http://172.16.0.55:51705/admin/documents'
|
||||
},
|
||||
|
||||
// 云浮
|
||||
'51706': {
|
||||
baseUrl: 'http://172.16.0.55:51706',
|
||||
documentUrl: 'http://172.16.0.55:51706/docauditai/',
|
||||
uploadUrl: 'http://172.16.0.55:51706/admin/documents'
|
||||
},
|
||||
|
||||
// 梅州
|
||||
'51707': {
|
||||
baseUrl: 'http://172.16.0.55:51707',
|
||||
documentUrl: 'http://172.16.0.55:51707/docauditai/',
|
||||
uploadUrl: 'http://172.16.0.55:51707/admin/documents'
|
||||
},
|
||||
|
||||
// 省局
|
||||
'51708': {
|
||||
baseUrl: 'http://172.16.0.55:51708',
|
||||
documentUrl: 'http://172.16.0.55:51708/docauditai/',
|
||||
@@ -86,14 +137,19 @@ const configs: Record<string, ApiConfig> = {
|
||||
|
||||
// 测试环境
|
||||
testing: {
|
||||
baseUrl: 'http://nas.7bm.co:3000',
|
||||
documentUrl: 'http://nas.7bm.co:9000/docauditai/',
|
||||
uploadUrl: 'http://172.16.0.58:8008/admin/documents/upload',
|
||||
baseUrl: 'http://172.16.0.55:8008',
|
||||
// baseUrl: 'http://172.16.0.81:3000',
|
||||
// baseUrl: 'http://nas.7bm.co:3000',
|
||||
// documentUrl: 'http://172.16.0.81:9000/docauditai/',
|
||||
documentUrl: 'http://172.16.0.55:8008/docauditai/',
|
||||
uploadUrl: 'http://172.16.0.55:8008/admin/documents',
|
||||
// uploadUrl: 'http://172.16.0.58:8008/admin/documents',
|
||||
// uploadUrl: 'http://172.16.0.58:8008/admin/documents',
|
||||
oauth: {
|
||||
serverUrl: 'http://10.79.112.85', // IDaaS服务器地址
|
||||
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO', // 需要替换为实际的Client ID
|
||||
clientSecret: 'your_client_secret', // 需要替换为实际的Client Secret
|
||||
redirectUri: 'http://nas.7bm.co:3000/callback', // 回调地址
|
||||
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
|
||||
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb', // 需要替换为实际的Client Secret
|
||||
redirectUri: 'http://10.79.97.17/', // 回调地址
|
||||
appId: 'idaasoauth2' // 应用ID,用于登出
|
||||
}
|
||||
},
|
||||
@@ -101,8 +157,8 @@ const configs: Record<string, ApiConfig> = {
|
||||
// 生产环境
|
||||
production: {
|
||||
// postgrest
|
||||
baseUrl: 'http://172.16.0.55:8008',
|
||||
// baseUrl: 'http://10.79.97.17:8000',
|
||||
// baseUrl: 'http://172.16.0.55:8008',
|
||||
baseUrl: 'http://10.79.97.17:8000',
|
||||
// minio
|
||||
documentUrl: 'http://10.76.244.156:9000/docauditai/',
|
||||
// 文件上传
|
||||
@@ -133,8 +189,31 @@ const configs: Record<string, ApiConfig> = {
|
||||
|
||||
// 获取当前环境,默认为development
|
||||
const getCurrentEnvironment = (): string => {
|
||||
// 优先使用环境变量,然后使用 NODE_ENV
|
||||
return process.env.NEXT_PUBLIC_API_ENV || process.env.NODE_ENV || 'development';
|
||||
// 在服务器端,优先使用PM2设置的环境变量
|
||||
if (typeof window === 'undefined') {
|
||||
// 服务器端:直接使用process.env.NODE_ENV
|
||||
const nodeEnv = process.env.NODE_ENV;
|
||||
console.log('🔧 服务器端环境检测:', {
|
||||
NODE_ENV: nodeEnv,
|
||||
result: nodeEnv || 'development'
|
||||
});
|
||||
return nodeEnv || 'development';
|
||||
}
|
||||
|
||||
// 客户端:优先使用NEXT_PUBLIC_前缀的环境变量
|
||||
const nextPublicNodeEnv = process.env.NEXT_PUBLIC_NODE_ENV;
|
||||
const nextPublicEnv = process.env.NEXT_PUBLIC_API_ENV;
|
||||
const nodeEnv = process.env.NODE_ENV;
|
||||
const result = nextPublicNodeEnv || nextPublicEnv || nodeEnv || 'development';
|
||||
|
||||
console.log('🔧 客户端环境检测:', {
|
||||
NEXT_PUBLIC_NODE_ENV: nextPublicNodeEnv,
|
||||
NEXT_PUBLIC_API_ENV: nextPublicEnv,
|
||||
NODE_ENV: nodeEnv,
|
||||
result: result
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
// 从环境变量获取配置,如果环境变量不存在则使用默认配置
|
||||
@@ -155,20 +234,67 @@ const getConfigFromEnv = (defaultConfig: ApiConfig): ApiConfig => {
|
||||
|
||||
/**
|
||||
* 获取当前端口号
|
||||
* 优先从环境变量获取,然后从浏览器location获取
|
||||
* 优先从浏览器location获取,然后从环境变量获取
|
||||
*/
|
||||
const getCurrentPort = (): string => {
|
||||
// 在客户端,优先从浏览器location获取端口
|
||||
let windowPort = '';
|
||||
if (typeof window !== 'undefined') {
|
||||
windowPort = window.location.port || '';
|
||||
}
|
||||
|
||||
// 在服务器端,优先使用运行时端口检测
|
||||
if (typeof window === 'undefined') {
|
||||
const runtimePort = getRuntimePort();
|
||||
if (runtimePort) {
|
||||
console.log('🔧 服务器端运行时端口检测:', runtimePort);
|
||||
return runtimePort;
|
||||
}
|
||||
}
|
||||
|
||||
// 优先使用环境变量中的端口配置
|
||||
if (process.env.API_PORT_CONFIG) {
|
||||
return process.env.API_PORT_CONFIG;
|
||||
const nextPublicApiPortConfig = process.env.NEXT_PUBLIC_API_PORT_CONFIG;
|
||||
const nextPublicPort = process.env.NEXT_PUBLIC_PORT;
|
||||
const apiPortConfig = process.env.API_PORT_CONFIG;
|
||||
const portEnv = process.env.PORT;
|
||||
|
||||
// 优先级:windowPort > NEXT_PUBLIC_API_PORT_CONFIG > NEXT_PUBLIC_PORT > API_PORT_CONFIG > PORT环境变量
|
||||
const result = windowPort || nextPublicApiPortConfig || nextPublicPort || apiPortConfig || portEnv || '';
|
||||
|
||||
console.log('🔧 端口检测:', {
|
||||
windowPort: windowPort,
|
||||
NEXT_PUBLIC_API_PORT_CONFIG: nextPublicApiPortConfig,
|
||||
NEXT_PUBLIC_PORT: nextPublicPort,
|
||||
API_PORT_CONFIG: apiPortConfig,
|
||||
PORT: portEnv,
|
||||
result: result
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* 运行时端口检测 - 从服务器启动参数或环境变量获取实际端口
|
||||
* 这个方法只在服务器端运行,用于动态获取实际运行端口
|
||||
*/
|
||||
const getRuntimePort = (): string => {
|
||||
if (typeof window !== 'undefined') {
|
||||
return ''; // 客户端不执行此逻辑
|
||||
}
|
||||
|
||||
// 如果是浏览器环境,从location获取端口
|
||||
if (typeof window !== 'undefined' && window.location.port) {
|
||||
return window.location.port;
|
||||
// 尝试从进程参数中获取端口
|
||||
const args = process.argv;
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
if (args[i] === '--port' && i + 1 < args.length) {
|
||||
return args[i + 1];
|
||||
}
|
||||
if (args[i].startsWith('--port=')) {
|
||||
return args[i].split('=')[1];
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
// 从环境变量获取
|
||||
return process.env.PORT || '';
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -179,24 +305,40 @@ const getCurrentConfig = (): ApiConfig => {
|
||||
const env = getCurrentEnvironment();
|
||||
const port = getCurrentPort();
|
||||
|
||||
console.log('🔧 配置调试信息:', {
|
||||
environment: env,
|
||||
port: port,
|
||||
hasPortConfig: !!(port && portConfigs[port]),
|
||||
portConfig: port ? portConfigs[port] : null
|
||||
});
|
||||
|
||||
// 获取基础配置
|
||||
let defaultConfig = configs[env] || configs.development;
|
||||
|
||||
// 如果有端口特定配置,则合并配置
|
||||
if (port && portConfigs[port]) {
|
||||
console.log(`🔧 使用端口特定配置: ${port}`, portConfigs[port]);
|
||||
defaultConfig = {
|
||||
...defaultConfig,
|
||||
...portConfigs[port],
|
||||
// 保持oauth配置不变,只覆盖API相关配置
|
||||
oauth: defaultConfig.oauth
|
||||
};
|
||||
} else {
|
||||
console.log(`🔧 使用环境配置: ${env}`, defaultConfig);
|
||||
}
|
||||
|
||||
// 如果是浏览器环境,尝试从环境变量覆盖配置
|
||||
if (typeof window !== 'undefined' || process.env.NEXT_PUBLIC_API_BASE_URL) {
|
||||
// 只有在明确设置了环境变量的情况下才覆盖配置
|
||||
const hasEnvOverrides = process.env.NEXT_PUBLIC_API_BASE_URL ||
|
||||
process.env.NEXT_PUBLIC_DOCUMENT_URL ||
|
||||
process.env.NEXT_PUBLIC_UPLOAD_URL;
|
||||
|
||||
if (hasEnvOverrides) {
|
||||
console.log('🔧 检测到环境变量覆盖,使用环境变量配置');
|
||||
return getConfigFromEnv(defaultConfig);
|
||||
}
|
||||
|
||||
console.log('🔧 最终配置:', defaultConfig);
|
||||
return defaultConfig;
|
||||
};
|
||||
|
||||
@@ -234,9 +376,12 @@ export const getCurrentPortConfig = () => {
|
||||
};
|
||||
|
||||
// 调试信息(仅在开发环境显示)
|
||||
// if (process.env.NODE_ENV === 'development') {
|
||||
// console.log('📦 API配置信息:', {
|
||||
// environment: getCurrentEnvironment(),
|
||||
// config: apiConfig
|
||||
// });
|
||||
// }
|
||||
if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
|
||||
console.log('📦 API配置信息:', {
|
||||
environment: getCurrentEnvironment(),
|
||||
currentEnv: process.env.NODE_ENV,
|
||||
nextPublicEnv: process.env.NEXT_PUBLIC_API_ENV,
|
||||
port: getCurrentPort(),
|
||||
config: apiConfig
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user