准备重构nginx的配置,先回退api-config配置,添加PM2的多端口服务的启动脚步
This commit is contained in:
@@ -21,7 +21,7 @@ export type QueryParams = Record<string, string | number | boolean | undefined>;
|
||||
// const API_BASE_URL = 'http://172.16.0.119:9000/admin';
|
||||
|
||||
// 调试:打印当前API_BASE_URL的值
|
||||
console.log('🔍 axios-client.ts - API_BASE_URL.value:', API_BASE_URL.value);
|
||||
console.log('🔍 axios-client.ts - API_BASE_URL:', API_BASE_URL);
|
||||
|
||||
// 文档URL前缀 (从配置文件导入)
|
||||
// export const DOCUMENT_URL = 'http://nas.7bm.co:9000/docauditai/';
|
||||
@@ -35,7 +35,7 @@ const DEFAULT_TIMEOUT = 30000; // 增加到30秒
|
||||
|
||||
// 创建 axios 实例
|
||||
const axiosInstance = axios.create({
|
||||
baseURL: API_BASE_URL.value === '/api' ? '' : API_BASE_URL.value, // 如果是相对路径,则不设置baseURL
|
||||
baseURL: API_BASE_URL,
|
||||
timeout: DEFAULT_TIMEOUT, // 增加超时时间
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -101,13 +101,13 @@ function buildUrl(endpoint: string, params?: QueryParams): string {
|
||||
fullUrl = endpoint;
|
||||
} else {
|
||||
// 处理相对路径的情况
|
||||
if (API_BASE_URL.value === '/api') {
|
||||
if (API_BASE_URL === '/api') {
|
||||
// 如果是相对路径,直接使用endpoint
|
||||
const path = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
|
||||
fullUrl = path;
|
||||
} else {
|
||||
// 确保API_BASE_URL格式正确
|
||||
const baseUrl = API_BASE_URL.value.endsWith('/') ? API_BASE_URL.value.slice(0, -1) : API_BASE_URL.value;
|
||||
const baseUrl = API_BASE_URL.endsWith('/') ? API_BASE_URL.slice(0, -1) : API_BASE_URL;
|
||||
const path = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
|
||||
fullUrl = `${baseUrl}${path}`;
|
||||
}
|
||||
@@ -200,7 +200,7 @@ export async function apiRequest<T>(
|
||||
return getMockResponse<T>(endpoint);
|
||||
}
|
||||
|
||||
console.log('api-base-url-----------',API_BASE_URL.value)
|
||||
console.log('api-base-url-----------',API_BASE_URL)
|
||||
|
||||
try {
|
||||
// 构建 URL
|
||||
|
||||
@@ -133,7 +133,7 @@ export async function submitCrossCheckingOpinion(
|
||||
evaluation_result_id: opinionData.reviewPointResultId
|
||||
};
|
||||
|
||||
const response = await fetch(`${API_BASE_URL.value}/admin/cross_review/proposals`, {
|
||||
const response = await fetch(`${API_BASE_URL}/admin/cross_review/proposals`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -189,7 +189,7 @@ export async function getCrossCheckingOpinions(
|
||||
// 如果没传userId,默认用1
|
||||
const realUserId = userId ?? 1;
|
||||
// 实际后端API调用,拼接API_BASE_URL
|
||||
const response = await fetch(`${API_BASE_URL.value}/admin/cross_review/proposals/document`, {
|
||||
const response = await fetch(`${API_BASE_URL}/admin/cross_review/proposals/document`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -303,24 +303,24 @@ export async function performOpinionAction(
|
||||
switch (actionData.action) {
|
||||
case 'agree':
|
||||
message = '已赞同该意见';
|
||||
endpoint = `${API_BASE_URL.value}/admin/cross_review/proposals/${actionData.opinionId}/votes`;
|
||||
endpoint = `${API_BASE_URL}/admin/cross_review/proposals/${actionData.opinionId}/votes`;
|
||||
requestBody = { vote_type: 'agree', voter_id: userInfo?.user_id };
|
||||
break;
|
||||
case 'disagree':
|
||||
message = '已反对该意见';
|
||||
endpoint = `${API_BASE_URL.value}/admin/cross_review/proposals/${actionData.opinionId}/votes`;
|
||||
endpoint = `${API_BASE_URL}/admin/cross_review/proposals/${actionData.opinionId}/votes`;
|
||||
requestBody = { vote_type: 'disagree', voter_id: userInfo?.user_id };
|
||||
break;
|
||||
case 'withdraw_vote':
|
||||
message = '已撤销投票';
|
||||
// 撤销投票的接口,根据实际API调整
|
||||
endpoint = `${API_BASE_URL.value}/admin/cross_review/proposals/${actionData.opinionId}/votes`;
|
||||
endpoint = `${API_BASE_URL}/admin/cross_review/proposals/${actionData.opinionId}/votes`;
|
||||
requestBody = { vote_type: 'cancel', voter_id: userInfo?.user_id };
|
||||
break;
|
||||
case 'withdraw_opinion':
|
||||
message = '已撤销意见';
|
||||
// 撤销意见的接口,根据实际API调整
|
||||
endpoint = `${API_BASE_URL.value}/admin/cross_review/proposals/${actionData.opinionId}`;
|
||||
endpoint = `${API_BASE_URL}/admin/cross_review/proposals/${actionData.opinionId}`;
|
||||
requestBody = {};
|
||||
break;
|
||||
default:
|
||||
@@ -415,7 +415,7 @@ export async function checkProposalVotes(
|
||||
document_id: documentId
|
||||
};
|
||||
|
||||
const response = await fetch(`${API_BASE_URL.value}/admin/cross_review/proposals/document/check_pending_votes`, {
|
||||
const response = await fetch(`${API_BASE_URL}/admin/cross_review/proposals/document/check_pending_votes`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
@@ -389,7 +389,7 @@ export async function getCrossCheckingStats(userInfo?: { user_id?: number; [key:
|
||||
export async function getUserTaskDocuments(page: number = 1, pageSize: number = 10, jwtToken?: string): Promise<ApiResponse<UserTaskApiResponse>> {
|
||||
try {
|
||||
// 拼接绝对路径,去除多余斜杠
|
||||
const base = API_BASE_URL.value.endsWith('/') ? API_BASE_URL.value.slice(0, -1) : API_BASE_URL.value;
|
||||
const base = API_BASE_URL.endsWith('/') ? API_BASE_URL.slice(0, -1) : API_BASE_URL;
|
||||
const url = `${base}/admin/cross_review/tasks/user_tasks`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
@@ -436,7 +436,7 @@ export async function getUserTaskDocuments(page: number = 1, pageSize: number =
|
||||
export async function getTaskDocuments(taskId: number, page: number = 1, pageSize: number = 10, jwtToken?: string): Promise<ApiResponse<TaskDocumentApiResponse>> {
|
||||
try {
|
||||
// 拼接绝对路径,去除多余斜杠
|
||||
const base = API_BASE_URL.value.endsWith('/') ? API_BASE_URL.value.slice(0, -1) : API_BASE_URL.value;
|
||||
const base = API_BASE_URL.endsWith('/') ? API_BASE_URL.slice(0, -1) : API_BASE_URL;
|
||||
const url = `${base}/admin/cross_review/tasks/${taskId}/documents`;
|
||||
// console.log('最终请求URL:', url);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ export class TokenManager {
|
||||
private oauthClient: OAuthClient;
|
||||
|
||||
constructor() {
|
||||
this.oauthClient = new OAuthClient(OAUTH_CONFIG.value);
|
||||
this.oauthClient = new OAuthClient(OAUTH_CONFIG);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,7 +57,7 @@ export async function getOrganizationTree(includeUsers: boolean = true, jwtToken
|
||||
|
||||
if (jwtToken) {
|
||||
// 如果提供了JWT Token,则使用fetch并携带Authorization头
|
||||
const url = `${API_BASE_URL.value}/admin/users/organizations?include_users=${includeUsers}`;
|
||||
const url = `${API_BASE_URL}/admin/users/organizations?include_users=${includeUsers}`;
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${jwtToken}`,
|
||||
|
||||
@@ -769,7 +769,7 @@ export function ReviewPointsList({
|
||||
// console.log('最终请求体:', data);
|
||||
// 用原生 fetch + application/json 提交
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL.value.replace(/\/$/, '')}/admin/cross_review/proposals`, {
|
||||
const response = await fetch(`${API_BASE_URL.replace(/\/$/, '')}/admin/cross_review/proposals`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
+93
-225
@@ -27,26 +27,54 @@ interface ApiConfig {
|
||||
};
|
||||
}
|
||||
|
||||
// 端口特定配置映射
|
||||
// 根据不同端口提供不同的API配置
|
||||
const portConfigs: Record<string, Partial<ApiConfig>> = {
|
||||
'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/',
|
||||
uploadUrl: 'http://172.16.0.55:51708/admin/documents'
|
||||
}
|
||||
};
|
||||
|
||||
// 不同环境的默认配置
|
||||
// 由于合同模板的上传,后续的的uploadUrl都不需要/upload,直接写/admin/documents,由程序自动添加/upload或/upload_contract_template
|
||||
const configs: Record<string, ApiConfig> = {
|
||||
// 开发环境
|
||||
development: {
|
||||
// baseUrl: '/api', // 改为相对路径,让nginx处理
|
||||
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/',
|
||||
// documentUrl: '/api/docauditai/',
|
||||
|
||||
// uploadUrl: '/api/admin/documents', // 改为相对路径
|
||||
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',
|
||||
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb', // 需要替换为实际的Client Secret
|
||||
redirectUri: 'http://10.79.97.17/callback', // 回调地址
|
||||
redirectUri: 'http://10.79.97.17/', // 回调地址
|
||||
appId: 'idaasoauth2' // 应用ID,用于登出
|
||||
}
|
||||
},
|
||||
@@ -77,8 +105,7 @@ const configs: Record<string, ApiConfig> = {
|
||||
serverUrl: 'http://10.79.112.85', // IDaaS服务器地址
|
||||
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
|
||||
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb', // 需要替换为实际的Client Secret
|
||||
redirectUri: 'http://10.79.97.17/callback', // 回调地址
|
||||
|
||||
redirectUri: 'http://10.79.97.17/', // 回调地址
|
||||
appId: 'idaasoauth2' // 应用ID,用于登出
|
||||
}
|
||||
},
|
||||
@@ -98,165 +125,12 @@ const configs: Record<string, ApiConfig> = {
|
||||
}
|
||||
};
|
||||
|
||||
// 客户端特定配置 - 支持多客户端部署
|
||||
// 根据环境自动选择配置
|
||||
const getClientConfigs = (env: string): Record<string, Partial<ApiConfig>> => {
|
||||
if (env === 'development') {
|
||||
// 开发环境 - 本地nginx代理配置
|
||||
return {
|
||||
'client-a': {
|
||||
baseUrl: '/api', // 改为相对路径,让nginx处理
|
||||
uploadUrl: '/api/admin/documents', // 改为相对路径
|
||||
documentUrl: '/api/docauditai/',
|
||||
oauth: {
|
||||
serverUrl: 'http://10.79.112.85',
|
||||
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
|
||||
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb',
|
||||
redirectUri: 'http://172.16.0.34:5174/callback',
|
||||
appId: 'idaasoauth2'
|
||||
}
|
||||
},
|
||||
'client-b': {
|
||||
baseUrl: '/api', // 改为相对路径,让nginx处理
|
||||
uploadUrl: '/api/admin/documents', // 改为相对路径
|
||||
documentUrl: '/api/docauditai/',
|
||||
oauth: {
|
||||
serverUrl: 'http://10.79.112.85',
|
||||
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
|
||||
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb',
|
||||
redirectUri: 'http://172.16.0.34:5175/callback',
|
||||
appId: 'idaasoauth2'
|
||||
}
|
||||
},
|
||||
'client-c': {
|
||||
baseUrl: '/api', // 改为相对路径,让nginx处理
|
||||
uploadUrl: '/api/admin/documents', // 改为相对路径
|
||||
documentUrl: '/api/docauditai/',
|
||||
oauth: {
|
||||
serverUrl: 'http://10.79.112.85',
|
||||
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
|
||||
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb',
|
||||
redirectUri: 'http://172.16.0.34:5176/callback',
|
||||
appId: 'idaasoauth2'
|
||||
}
|
||||
},
|
||||
'client-d': {
|
||||
baseUrl: '/api', // 改为相对路径,让nginx处理
|
||||
uploadUrl: '/api/admin/documents', // 改为相对路径
|
||||
documentUrl: '/api/docauditai/',
|
||||
oauth: {
|
||||
serverUrl: 'http://10.79.112.85',
|
||||
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
|
||||
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb',
|
||||
redirectUri: 'http://172.16.0.34:5177/callback',
|
||||
appId: 'idaasoauth2'
|
||||
}
|
||||
}
|
||||
};
|
||||
} else {
|
||||
// 生产环境 - 服务器配置
|
||||
return {
|
||||
'provincial': {
|
||||
baseUrl: 'http://10.79.97.17:51704',
|
||||
uploadUrl: 'http://10.79.97.17:51704/admin/documents',
|
||||
documentUrl: 'http://10.76.244.156:9000/docauditai/',
|
||||
oauth: {
|
||||
serverUrl: 'http://10.79.112.85',
|
||||
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
|
||||
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb',
|
||||
redirectUri: 'http://10.79.97.17/callback',
|
||||
appId: 'idaasoauth2'
|
||||
}
|
||||
},
|
||||
'meizhou': {
|
||||
baseUrl: 'http://10.79.97.17:51705',
|
||||
uploadUrl: 'http://10.79.97.17:51705/admin/documents',
|
||||
documentUrl: 'http://10.76.244.156:9000/docauditai/',
|
||||
oauth: {
|
||||
serverUrl: 'http://10.79.112.85',
|
||||
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
|
||||
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb',
|
||||
redirectUri: 'http://10.79.97.17/callback',
|
||||
appId: 'idaasoauth2'
|
||||
}
|
||||
},
|
||||
'jieyang': {
|
||||
baseUrl: 'http://10.79.97.17:51706',
|
||||
uploadUrl: 'http://10.79.97.17:51706/admin/documents',
|
||||
documentUrl: 'http://10.76.244.156:9000/docauditai/',
|
||||
oauth: {
|
||||
serverUrl: 'http://10.79.112.85',
|
||||
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
|
||||
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb',
|
||||
redirectUri: 'http://10.79.97.17/callback',
|
||||
appId: 'idaasoauth2'
|
||||
}
|
||||
},
|
||||
'yunfu': {
|
||||
baseUrl: 'http://10.79.97.17:51707',
|
||||
uploadUrl: 'http://10.79.97.17:51707/admin/documents',
|
||||
documentUrl: 'http://10.76.244.156:9000/docauditai/',
|
||||
oauth: {
|
||||
serverUrl: 'http://10.79.112.85',
|
||||
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
|
||||
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb',
|
||||
redirectUri: 'http://10.79.97.17/callback',
|
||||
appId: 'idaasoauth2'
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// 获取当前环境,默认为development
|
||||
const getCurrentEnvironment = (): string => {
|
||||
// 优先使用环境变量,然后使用 NODE_ENV
|
||||
return process.env.NEXT_PUBLIC_API_ENV || process.env.NODE_ENV || 'development';
|
||||
};
|
||||
|
||||
// 获取客户端ID - 支持从请求头动态获取
|
||||
const getClientId = (request?: Request): string => {
|
||||
// SSR: 通过请求头的 host 判断
|
||||
if (request && typeof window === 'undefined') {
|
||||
// 1. 优先 X-Client-ID
|
||||
const clientIdFromHeader = request.headers.get('X-Client-ID');
|
||||
if (clientIdFromHeader) return clientIdFromHeader;
|
||||
|
||||
// 2. 通过 host 端口判断
|
||||
const host = request.headers.get('host'); // 例如 172.24.238.60:5177
|
||||
if (host) {
|
||||
const port = host.split(':')[1];
|
||||
const portToClient: Record<string, string> = {
|
||||
'5174': 'client-a',
|
||||
'5175': 'client-b',
|
||||
'5176': 'client-c',
|
||||
'5177': 'client-d'
|
||||
};
|
||||
if (port && portToClient[port]) {
|
||||
return portToClient[port];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 浏览器端
|
||||
if (typeof window !== 'undefined') {
|
||||
const port = window.location.port;
|
||||
const portToClient: Record<string, string> = {
|
||||
'5174': 'client-a',
|
||||
'5175': 'client-b',
|
||||
'5176': 'client-c',
|
||||
'5177': 'client-d'
|
||||
};
|
||||
if (port && portToClient[port]) {
|
||||
console.log(`🎯 浏览器端检测到客户端ID: ${portToClient[port]} (端口: ${port})`);
|
||||
return portToClient[port];
|
||||
}
|
||||
}
|
||||
|
||||
// 回退到环境变量
|
||||
return process.env.CLIENT_ID || process.env.NEXT_PUBLIC_CLIENT_ID || 'main';
|
||||
};
|
||||
|
||||
// 从环境变量获取配置,如果环境变量不存在则使用默认配置
|
||||
const getConfigFromEnv = (defaultConfig: ApiConfig): ApiConfig => {
|
||||
return {
|
||||
@@ -273,83 +147,63 @@ const getConfigFromEnv = (defaultConfig: ApiConfig): ApiConfig => {
|
||||
};
|
||||
};
|
||||
|
||||
// 获取当前配置 - 支持客户端特定配置
|
||||
const getCurrentConfig = (request?: Request): ApiConfig => {
|
||||
/**
|
||||
* 获取当前端口号
|
||||
* 优先从环境变量获取,然后从浏览器location获取
|
||||
*/
|
||||
const getCurrentPort = (): string => {
|
||||
// 优先使用环境变量中的端口配置
|
||||
if (process.env.API_PORT_CONFIG) {
|
||||
return process.env.API_PORT_CONFIG;
|
||||
}
|
||||
|
||||
// 如果是浏览器环境,从location获取端口
|
||||
if (typeof window !== 'undefined' && window.location.port) {
|
||||
return window.location.port;
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取当前配置
|
||||
* 支持根据端口动态切换API配置
|
||||
*/
|
||||
const getCurrentConfig = (): ApiConfig => {
|
||||
const env = getCurrentEnvironment();
|
||||
const clientId = getClientId(request);
|
||||
const defaultConfig = configs[env] || configs.development;
|
||||
const port = getCurrentPort();
|
||||
|
||||
// 获取当前环境的客户端特定配置
|
||||
const clientConfigs = getClientConfigs(env);
|
||||
const clientConfig = clientConfigs[clientId];
|
||||
// 获取基础配置
|
||||
let defaultConfig = configs[env] || configs.development;
|
||||
|
||||
// 合并默认配置和客户端特定配置
|
||||
let finalConfig = defaultConfig;
|
||||
if (clientConfig) {
|
||||
finalConfig = {
|
||||
...defaultConfig,
|
||||
...clientConfig,
|
||||
oauth: {
|
||||
...defaultConfig.oauth,
|
||||
...clientConfig.oauth
|
||||
}
|
||||
// 如果有端口特定配置,则合并配置
|
||||
if (port && portConfigs[port]) {
|
||||
defaultConfig = {
|
||||
...defaultConfig,
|
||||
...portConfigs[port],
|
||||
// 保持oauth配置不变,只覆盖API相关配置
|
||||
oauth: defaultConfig.oauth
|
||||
};
|
||||
}
|
||||
|
||||
// 如果是浏览器环境,尝试从环境变量覆盖配置
|
||||
if (typeof window !== 'undefined' || process.env.NEXT_PUBLIC_API_BASE_URL) {
|
||||
return getConfigFromEnv(finalConfig);
|
||||
return getConfigFromEnv(defaultConfig);
|
||||
}
|
||||
|
||||
return finalConfig;
|
||||
return defaultConfig;
|
||||
};
|
||||
|
||||
// 导出当前环境的配置(静态,用于兼容性)
|
||||
// 导出当前环境的配置
|
||||
export const apiConfig = getCurrentConfig();
|
||||
|
||||
// 导出动态配置获取函数(支持从请求头获取客户端ID)
|
||||
export const getApiConfig = (request?: Request): ApiConfig => {
|
||||
return getCurrentConfig(request);
|
||||
};
|
||||
|
||||
// 导出具体的配置项,方便使用(现在是真正动态的)
|
||||
// 使用getter函数实现动态获取,避免ES模块中exports未定义的问题
|
||||
export const API_BASE_URL = {
|
||||
get value() {
|
||||
return getCurrentConfig().baseUrl;
|
||||
}
|
||||
};
|
||||
|
||||
export const DOCUMENT_URL = {
|
||||
get value() {
|
||||
return getCurrentConfig().documentUrl;
|
||||
}
|
||||
};
|
||||
|
||||
export const UPLOAD_URL = {
|
||||
get value() {
|
||||
return getCurrentConfig().uploadUrl;
|
||||
}
|
||||
};
|
||||
|
||||
export const OAUTH_CONFIG = {
|
||||
get value() {
|
||||
return getCurrentConfig().oauth;
|
||||
}
|
||||
};
|
||||
|
||||
// 动态获取配置项的函数
|
||||
export const getApiBaseUrl = (request?: Request): string => {
|
||||
return getApiConfig(request).baseUrl;
|
||||
};
|
||||
|
||||
export const getUploadUrl = (request?: Request): string => {
|
||||
return getApiConfig(request).uploadUrl;
|
||||
};
|
||||
|
||||
export const getOAuthConfig = (request?: Request) => {
|
||||
return getApiConfig(request).oauth;
|
||||
};
|
||||
// 导出具体的配置项,方便使用
|
||||
export const {
|
||||
baseUrl: API_BASE_URL,
|
||||
documentUrl: DOCUMENT_URL,
|
||||
uploadUrl: UPLOAD_URL,
|
||||
oauth: OAUTH_CONFIG
|
||||
} = apiConfig;
|
||||
|
||||
// 导出所有配置,供调试使用
|
||||
export { configs };
|
||||
@@ -359,6 +213,20 @@ export const setEnvironment = (env: string): ApiConfig => {
|
||||
return configs[env] || configs.development;
|
||||
};
|
||||
|
||||
/**
|
||||
* 工具函数:获取当前端口配置信息(用于调试)
|
||||
*/
|
||||
export const getCurrentPortConfig = () => {
|
||||
const port = getCurrentPort();
|
||||
const env = getCurrentEnvironment();
|
||||
return {
|
||||
currentPort: port,
|
||||
currentEnvironment: env,
|
||||
hasPortConfig: !!(port && portConfigs[port]),
|
||||
portConfig: port ? portConfigs[port] : null
|
||||
};
|
||||
};
|
||||
|
||||
// 调试信息(仅在开发环境显示)
|
||||
// if (process.env.NODE_ENV === 'development') {
|
||||
// console.log('📦 API配置信息:', {
|
||||
|
||||
@@ -34,7 +34,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
|
||||
try {
|
||||
// 创建OAuth客户端
|
||||
const oauthClient = new OAuthClient(OAUTH_CONFIG.value);
|
||||
const oauthClient = new OAuthClient(OAUTH_CONFIG);
|
||||
|
||||
// 获取访问令牌
|
||||
const tokenResponse = await oauthClient.getAccessToken(code);
|
||||
|
||||
@@ -184,7 +184,7 @@ export default function Login() {
|
||||
const handleOAuthLogin = () => {
|
||||
try {
|
||||
// 创建OAuth客户端
|
||||
const oauthClient = new OAuthClient(OAUTH_CONFIG.value);
|
||||
const oauthClient = new OAuthClient(OAUTH_CONFIG);
|
||||
|
||||
// 生成状态值
|
||||
const state = oauthClient.generateState();
|
||||
@@ -205,8 +205,8 @@ export default function Login() {
|
||||
|
||||
useEffect(() => {
|
||||
// 检查OAuth配置是否完整
|
||||
if (!OAUTH_CONFIG.value.serverUrl || !OAUTH_CONFIG.value.clientId || !OAUTH_CONFIG.value.clientSecret) {
|
||||
console.error("OAuth2.0配置不完整:", OAUTH_CONFIG.value);
|
||||
if (!OAUTH_CONFIG.serverUrl || !OAUTH_CONFIG.clientId || !OAUTH_CONFIG.clientSecret) {
|
||||
console.error("OAuth2.0配置不完整:", OAUTH_CONFIG);
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
if (accessToken) {
|
||||
try {
|
||||
// 创建OAuth客户端
|
||||
const oauthClient = new OAuthClient(OAUTH_CONFIG.value);
|
||||
const oauthClient = new OAuthClient(OAUTH_CONFIG);
|
||||
|
||||
// 构建登出后重定向URL
|
||||
const url = new URL(request.url);
|
||||
|
||||
+123
-62
@@ -31,66 +31,7 @@ module.exports = {
|
||||
log_file: './logs/main-combined.log',
|
||||
time: true
|
||||
},
|
||||
// 客户端A - 反向代理服务 (端口: 51701)
|
||||
{
|
||||
name: 'docreview-client-a',
|
||||
script: 'node',
|
||||
args: [
|
||||
'-r', 'dotenv/config',
|
||||
'./node_modules/.bin/remix-serve',
|
||||
'./build/server/index.js'
|
||||
],
|
||||
instances: 1,
|
||||
autorestart: true,
|
||||
watch: false,
|
||||
max_memory_restart: '1G',
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
PORT: 51701,
|
||||
CLIENT_ID: 'client-a',
|
||||
PROXY_TARGET: 'http://10.79.97.17:51703'
|
||||
},
|
||||
env_testing: {
|
||||
NODE_ENV: 'testing',
|
||||
PORT: 51701,
|
||||
CLIENT_ID: 'client-a',
|
||||
PROXY_TARGET: 'http://10.79.97.17:51703'
|
||||
},
|
||||
error_file: './logs/client-a-err.log',
|
||||
out_file: './logs/client-a-out.log',
|
||||
log_file: './logs/client-a-combined.log',
|
||||
time: true
|
||||
},
|
||||
// 客户端B - 反向代理服务 (端口: 51702)
|
||||
{
|
||||
name: 'docreview-client-b',
|
||||
script: 'node',
|
||||
args: [
|
||||
'-r', 'dotenv/config',
|
||||
'./node_modules/.bin/remix-serve',
|
||||
'./build/server/index.js'
|
||||
],
|
||||
instances: 1,
|
||||
autorestart: true,
|
||||
watch: false,
|
||||
max_memory_restart: '1G',
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
PORT: 51702,
|
||||
CLIENT_ID: 'client-b',
|
||||
PROXY_TARGET: 'http://10.79.97.17:51703'
|
||||
},
|
||||
env_testing: {
|
||||
NODE_ENV: 'testing',
|
||||
PORT: 51702,
|
||||
CLIENT_ID: 'client-b',
|
||||
PROXY_TARGET: 'http://10.79.97.17:51703'
|
||||
},
|
||||
error_file: './logs/client-b-err.log',
|
||||
out_file: './logs/client-b-out.log',
|
||||
log_file: './logs/client-b-combined.log',
|
||||
time: true
|
||||
},
|
||||
|
||||
// 客户端C - 反向代理服务 (端口: 51704)
|
||||
{
|
||||
name: 'docreview-client-c',
|
||||
@@ -108,18 +49,138 @@ module.exports = {
|
||||
NODE_ENV: 'production',
|
||||
PORT: 51704,
|
||||
CLIENT_ID: 'client-c',
|
||||
PROXY_TARGET: 'http://10.79.97.17:51703'
|
||||
API_PORT_CONFIG: '51704'
|
||||
},
|
||||
env_testing: {
|
||||
NODE_ENV: 'testing',
|
||||
PORT: 51704,
|
||||
CLIENT_ID: 'client-c',
|
||||
PROXY_TARGET: 'http://10.79.97.17:51703'
|
||||
API_PORT_CONFIG: '51704'
|
||||
},
|
||||
error_file: './logs/client-c-err.log',
|
||||
out_file: './logs/client-c-out.log',
|
||||
log_file: './logs/client-c-combined.log',
|
||||
time: true
|
||||
},
|
||||
// 客户端D - 独立服务 (端口: 51705)
|
||||
{
|
||||
name: 'docreview-client-d',
|
||||
script: 'node',
|
||||
args: [
|
||||
'-r', 'dotenv/config',
|
||||
'./node_modules/.bin/remix-serve',
|
||||
'./build/server/index.js'
|
||||
],
|
||||
instances: 1,
|
||||
autorestart: true,
|
||||
watch: false,
|
||||
max_memory_restart: '1G',
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
PORT: 51705,
|
||||
CLIENT_ID: 'client-d',
|
||||
API_PORT_CONFIG: '51705'
|
||||
},
|
||||
env_testing: {
|
||||
NODE_ENV: 'testing',
|
||||
PORT: 51705,
|
||||
CLIENT_ID: 'client-d',
|
||||
API_PORT_CONFIG: '51705'
|
||||
},
|
||||
error_file: './logs/client-d-err.log',
|
||||
out_file: './logs/client-d-out.log',
|
||||
log_file: './logs/client-d-combined.log',
|
||||
time: true
|
||||
},
|
||||
// 客户端E - 独立服务 (端口: 51706)
|
||||
{
|
||||
name: 'docreview-client-e',
|
||||
script: 'node',
|
||||
args: [
|
||||
'-r', 'dotenv/config',
|
||||
'./node_modules/.bin/remix-serve',
|
||||
'./build/server/index.js'
|
||||
],
|
||||
instances: 1,
|
||||
autorestart: true,
|
||||
watch: false,
|
||||
max_memory_restart: '1G',
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
PORT: 51706,
|
||||
CLIENT_ID: 'client-e',
|
||||
API_PORT_CONFIG: '51706'
|
||||
},
|
||||
env_testing: {
|
||||
NODE_ENV: 'testing',
|
||||
PORT: 51706,
|
||||
CLIENT_ID: 'client-e',
|
||||
API_PORT_CONFIG: '51706'
|
||||
},
|
||||
error_file: './logs/client-e-err.log',
|
||||
out_file: './logs/client-e-out.log',
|
||||
log_file: './logs/client-e-combined.log',
|
||||
time: true
|
||||
},
|
||||
// 客户端F - 独立服务 (端口: 51707)
|
||||
{
|
||||
name: 'docreview-client-f',
|
||||
script: 'node',
|
||||
args: [
|
||||
'-r', 'dotenv/config',
|
||||
'./node_modules/.bin/remix-serve',
|
||||
'./build/server/index.js'
|
||||
],
|
||||
instances: 1,
|
||||
autorestart: true,
|
||||
watch: false,
|
||||
max_memory_restart: '1G',
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
PORT: 51707,
|
||||
CLIENT_ID: 'client-f',
|
||||
API_PORT_CONFIG: '51707'
|
||||
},
|
||||
env_testing: {
|
||||
NODE_ENV: 'testing',
|
||||
PORT: 51707,
|
||||
CLIENT_ID: 'client-f',
|
||||
API_PORT_CONFIG: '51707'
|
||||
},
|
||||
error_file: './logs/client-f-err.log',
|
||||
out_file: './logs/client-f-out.log',
|
||||
log_file: './logs/client-f-combined.log',
|
||||
time: true
|
||||
},
|
||||
// 客户端G - 独立服务 (端口: 51708)
|
||||
{
|
||||
name: 'docreview-client-g',
|
||||
script: 'node',
|
||||
args: [
|
||||
'-r', 'dotenv/config',
|
||||
'./node_modules/.bin/remix-serve',
|
||||
'./build/server/index.js'
|
||||
],
|
||||
instances: 1,
|
||||
autorestart: true,
|
||||
watch: false,
|
||||
max_memory_restart: '1G',
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
PORT: 51708,
|
||||
CLIENT_ID: 'client-g',
|
||||
API_PORT_CONFIG: '51708'
|
||||
},
|
||||
env_testing: {
|
||||
NODE_ENV: 'testing',
|
||||
PORT: 51708,
|
||||
CLIENT_ID: 'client-g',
|
||||
API_PORT_CONFIG: '51708'
|
||||
},
|
||||
error_file: './logs/client-g-err.log',
|
||||
out_file: './logs/client-g-out.log',
|
||||
log_file: './logs/client-g-combined.log',
|
||||
time: true
|
||||
}
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user