diff --git a/cookies.txt b/cookies.txt deleted file mode 100644 index a968e9f..0000000 --- a/cookies.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Netscape HTTP Cookie File -# https://curl.se/docs/http-cookies.html -# This file was generated by libcurl! Edit at your own risk. - -#HttpOnly_192.168.2.58 FALSE / FALSE 1760124244 sid Guest -192.168.2.58 FALSE / FALSE 0 system_user no -192.168.2.58 FALSE / FALSE 0 full_name Guest -192.168.2.58 FALSE / FALSE 0 user_id Guest -192.168.2.58 FALSE / FALSE 0 user_image diff --git a/frontend/.env.development b/frontend/.env.development new file mode 100644 index 0000000..30c0161 --- /dev/null +++ b/frontend/.env.development @@ -0,0 +1,5 @@ +## 前端环境变量 (Vite会读取VITE_前缀的变量) +# 开发环境:前端使用相对路径,通过Vite代理转发 +# 生产环境:前端直接请求后端服务器 +VITE_JINGROW_SERVER_URL= +VITE_BACKEND_SERVER_URL= diff --git a/frontend/ENV.md b/frontend/ENV.md deleted file mode 100644 index 5ab5d7c..0000000 --- a/frontend/ENV.md +++ /dev/null @@ -1,80 +0,0 @@ -# Jingrow Local 环境变量配置 - -## 快速开始 - -1. **复制环境变量文件**: - ```bash - cp env.example .env.local - ``` - -2. **编辑配置**: - ```bash - vim .env.local - ``` - -3. **重启开发服务器**: - ```bash - npm run dev - ``` - -## 环境变量说明 - -### Jingrow SaaS配置 -- `VITE_JINGROW_API_URL`: Jingrow SaaS API地址 - - 默认值: `https://cloud.jingrow.com` - - 用途: 登录、用户信息、数据存储等API调用 - -### 本地API配置 -- `VITE_LOCAL_API_URL`: 本地API服务地址 - - 默认值: `http://localhost:8000` - - 用途: 本地微服务API调用 - -### 应用配置 -- `VITE_APP_NAME`: 应用名称 - - 默认值: `Jingrow Local` -- `VITE_APP_VERSION`: 应用版本 - - 默认值: `1.0.0` - -## 不同环境配置 - -### 开发环境 (.env.local) -```env -VITE_JINGROW_API_URL=https://cloud.jingrow.com -VITE_LOCAL_API_URL=http://localhost:8000 -VITE_APP_NAME=Jingrow Local Dev -``` - -### 测试环境 (.env.test) -```env -VITE_JINGROW_API_URL=https://test.jingrow.com -VITE_LOCAL_API_URL=http://test-api:8000 -VITE_APP_NAME=Jingrow Local Test -``` - -### 生产环境 (.env.production) -```env -VITE_JINGROW_API_URL=https://cloud.jingrow.com -VITE_LOCAL_API_URL=https://api.jingrow.com -VITE_APP_NAME=Jingrow Local -``` - -## 注意事项 - -1. **Vite环境变量**:必须以 `VITE_` 开头才能在客户端访问 -2. **敏感信息**:不要在环境变量中存储敏感信息(如API密钥) -3. **版本控制**:`.env.local` 文件不应提交到版本控制系统 -4. **重启服务**:修改环境变量后需要重启开发服务器 - -## 使用示例 - -在代码中使用环境变量: - -```typescript -import env from '@/config/env' - -// 获取Jingrow API地址 -const apiUrl = env.JINGROW_API_URL - -// 获取应用名称 -const appName = env.APP_NAME -``` diff --git a/frontend/src/shared/api/agents.ts b/frontend/src/shared/api/agents.ts index 5014d07..451400e 100644 --- a/frontend/src/shared/api/agents.ts +++ b/frontend/src/shared/api/agents.ts @@ -7,7 +7,7 @@ import { deleteRecords, createRecord, updateRecord, getFieldSelectOptions, getRe export type { AIAgent, AgentExecutionResult } // 使用相对路径,通过Vite代理转发到后端 -const BACKEND_SERVER_URL = '' +const jingrowServerUrl = import.meta.env.VITE_JINGROW_SERVER_URL || '' // 获取Jingrow API鉴权头部 function get_jingrow_api_headers() { @@ -31,7 +31,7 @@ function get_jingrow_api_headers() { // 获取AI Agent列表 export const getAgentsApi = async (): Promise => { try { - const url = `${BACKEND_SERVER_URL}/api/action/jingrow.ai.utils.jflow.get_local_ai_agents_list` + const url = `${jingrowServerUrl}/api/action/jingrow.ai.utils.jflow.get_local_ai_agents_list` const requestData = { filters: [], @@ -84,7 +84,7 @@ export const getAgentDetail = async (name: string): Promise => { export const executeAgentApi = async (name: string): Promise<{ success: boolean; message?: string }> => { try { const response = await axios.post( - `${BACKEND_SERVER_URL}/api/action/jingrow.ai.utils.jflow.execute_local_ai_agent`, + `${jingrowServerUrl}/api/action/jingrow.ai.utils.jflow.execute_local_ai_agent`, { name: name }, @@ -117,7 +117,7 @@ export const executeAgentApi = async (name: string): Promise<{ success: boolean; export const updateAgentApi = async (name: string, data: Partial): Promise => { try { const response = await axios.post( - `${BACKEND_SERVER_URL}/api/action/jingrow.ai.utils.jflow.update_local_ai_agent`, + `${jingrowServerUrl}/api/action/jingrow.ai.utils.jflow.update_local_ai_agent`, { name: name, data: data diff --git a/frontend/src/shared/api/auth.ts b/frontend/src/shared/api/auth.ts index ca6b98b..189756b 100644 --- a/frontend/src/shared/api/auth.ts +++ b/frontend/src/shared/api/auth.ts @@ -1,3 +1,5 @@ +const jingrowServerUrl = import.meta.env.VITE_JINGROW_SERVER_URL || '' + export interface LoginResponse { message: string user: UserInfo @@ -28,7 +30,7 @@ export function getSessionCookie(): string | null { } export const loginApi = async (username: string, password: string): Promise => { - const response = await fetch('/api/action/login', { + const response = await fetch(`${jingrowServerUrl}/api/action/login`, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', @@ -58,7 +60,7 @@ export const loginApi = async (username: string, password: string): Promise => { - const response = await fetch('/api/action/jingrow.realtime.get_user_info', { + const response = await fetch(`${jingrowServerUrl}/api/action/jingrow.realtime.get_user_info`, { method: 'GET', headers: { 'Accept': 'application/json', @@ -87,7 +89,7 @@ export const getUserInfoApi = async (): Promise => { // 登出 export const logoutApi = async (): Promise => { - await fetch('/api/action/logout', { + await fetch(`${jingrowServerUrl}/api/action/logout`, { method: 'GET', headers: { 'Accept': 'application/json' }, credentials: 'include' diff --git a/frontend/src/shared/api/common.ts b/frontend/src/shared/api/common.ts index b717d65..91971ff 100644 --- a/frontend/src/shared/api/common.ts +++ b/frontend/src/shared/api/common.ts @@ -1,7 +1,7 @@ import axios from 'axios' import { get_session_api_headers } from './auth' -const BACKEND_SERVER_URL = '' +const jingrowServerUrl = import.meta.env.VITE_JINGROW_SERVER_URL || '' // 删除记录的通用函数 export const deleteRecords = async (pagetype: string, names: string[]): Promise<{ success: boolean; message?: string }> => { @@ -13,7 +13,7 @@ export const deleteRecords = async (pagetype: string, names: string[]): Promise< for (const name of names) { try { await axios.post( - `${BACKEND_SERVER_URL}/api/action/jingrow.client.delete`, + `${jingrowServerUrl}/api/action/jingrow.client.delete`, { pagetype: pagetype, name: name @@ -47,7 +47,7 @@ export const deleteRecords = async (pagetype: string, names: string[]): Promise< export const createRecord = async (pagetype: string, data: Record): Promise<{ success: boolean; data?: any; message?: string }> => { try { const response = await axios.post( - `${BACKEND_SERVER_URL}/api/data/${pagetype}`, + `${jingrowServerUrl}/api/data/${pagetype}`, data, { headers: get_session_api_headers(), @@ -67,7 +67,7 @@ export const createRecord = async (pagetype: string, data: Record): export const updateRecord = async (pagetype: string, name: string, data: Record): Promise<{ success: boolean; data?: any; message?: string }> => { try { const response = await axios.put( - `${BACKEND_SERVER_URL}/api/data/${pagetype}/${name}`, + `${jingrowServerUrl}/api/data/${pagetype}/${name}`, data, { headers: get_session_api_headers(), @@ -86,7 +86,7 @@ export const updateRecord = async (pagetype: string, name: string, data: Record< export const getRecord = async (pagetype: string, name: string): Promise<{ success: boolean; data?: any; message?: string }> => { try { const response = await axios.get( - `${BACKEND_SERVER_URL}/api/data/${pagetype}/${name}`, + `${jingrowServerUrl}/api/data/${pagetype}/${name}`, { headers: get_session_api_headers(), withCredentials: true @@ -107,7 +107,7 @@ export const getWorkspace = async (name: string): Promise<{ success: boolean; da export const getRecords = async (pagetype: string, filters: any[] = [], fields: string[] = [], orderBy: string = 'modified desc', limitStart: number = 0, limitPageLength: number = 20): Promise<{ success: boolean; data?: any[]; total?: number; message?: string }> => { try { const response = await axios.get( - `${BACKEND_SERVER_URL}/api/data/${pagetype}`, + `${jingrowServerUrl}/api/data/${pagetype}`, { params: { fields: JSON.stringify(fields), @@ -145,7 +145,7 @@ export const getRecords = async (pagetype: string, filters: any[] = [], fields: export const getFieldSelectOptions = async (pagetype: string, fieldname: string): Promise => { try { const res = await axios.post( - `${BACKEND_SERVER_URL}/api/action/jingrow.ai.utils.utils.get_field_select_options`, + `${jingrowServerUrl}/api/action/jingrow.ai.utils.utils.get_field_select_options`, { pagetype, fieldname }, { headers: get_session_api_headers(), withCredentials: true } ) @@ -179,7 +179,7 @@ export const uploadFileToJingrow = async ( } const response = await axios.post( - `${BACKEND_SERVER_URL}/api/action/upload_file`, + `${jingrowServerUrl}/api/action/upload_file`, formData, { headers: { diff --git a/frontend/src/shared/api/nodes.ts b/frontend/src/shared/api/nodes.ts index 40d1b1d..f8d92f7 100644 --- a/frontend/src/shared/api/nodes.ts +++ b/frontend/src/shared/api/nodes.ts @@ -2,7 +2,7 @@ import axios from 'axios' import { get_session_api_headers } from './auth' import { deleteRecords, createRecord, getFieldSelectOptions } from './common' -const BACKEND_SERVER_URL = '' +const jingrowServerUrl = import.meta.env.VITE_JINGROW_SERVER_URL || '' // 使用通用函数,这里可以保留别名或直接使用 export { getFieldSelectOptions as getNodeFieldSelectOptions } from './common' @@ -16,7 +16,7 @@ export const checkNodeTypeExists = async (nodeType: string): Promise => if (!nodeType) return false try { const response = await axios.post( - `${BACKEND_SERVER_URL}/api/action/jingrow.ai.utils.jflow.check_node_type_exists`, + `${jingrowServerUrl}/api/action/jingrow.ai.utils.jflow.check_node_type_exists`, { node_type: nodeType }, { headers: get_session_api_headers(), withCredentials: true } ) @@ -41,7 +41,7 @@ export const deleteNodes = async (names: string[]): Promise<{ success: boolean; export const getNodeRecord = async (name: string): Promise => { try { const response = await axios.get( - `${BACKEND_SERVER_URL}/api/action/jingrow.ai.utils.jflow.get_node_record`, + `${jingrowServerUrl}/api/action/jingrow.ai.utils.jflow.get_node_record`, { params: { name }, headers: get_session_api_headers(), @@ -59,7 +59,7 @@ export const getNodeRecord = async (name: string): Promise => { export const updateNode = async (name: string, nodeData: any): Promise => { try { const response = await axios.post( - `${BACKEND_SERVER_URL}/api/action/jingrow.ai.utils.jflow.update_node`, + `${jingrowServerUrl}/api/action/jingrow.ai.utils.jflow.update_node`, { name, node_data: nodeData }, { headers: get_session_api_headers(), withCredentials: true } ) @@ -74,7 +74,7 @@ export const updateNode = async (name: string, nodeData: any): Promise => { export const getNodeByType = async (nodeType: string): Promise => { try { const response = await axios.post( - `${BACKEND_SERVER_URL}/api/action/jingrow.ai.utils.jflow.get_node_by_type`, + `${jingrowServerUrl}/api/action/jingrow.ai.utils.jflow.get_node_by_type`, { node_type: nodeType }, { headers: get_session_api_headers(), withCredentials: true } ) @@ -89,7 +89,7 @@ export const getNodeByType = async (nodeType: string): Promise => { export const getNodeSchemaFields = async (nodeType: string): Promise => { try { const response = await axios.post( - `${BACKEND_SERVER_URL}/api/action/jingrow.ai.utils.jflow.get_node_schema_fields`, + `${jingrowServerUrl}/api/action/jingrow.ai.utils.jflow.get_node_schema_fields`, { node_type: nodeType }, { headers: get_session_api_headers(), withCredentials: true } ) @@ -109,7 +109,7 @@ export const getNodeList = async (page: number = 1, pageSize: number = 10): Prom }) const response = await axios.get( - `${BACKEND_SERVER_URL}/api/action/jingrow.ai.utils.jflow.get_node_list?${params}`, + `${jingrowServerUrl}/api/action/jingrow.ai.utils.jflow.get_node_list?${params}`, { headers: get_session_api_headers(), withCredentials: true } ) return response.data?.message || response.data diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index 430fe8d..c344c5a 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -3,7 +3,8 @@ "target": "ES2020", "useDefineForClassFields": true, "lib": ["ES2020", "DOM", "DOM.Iterable"], - "module": "ESNext", + "module": "ES2022", + "types": ["vite/client"], "skipLibCheck": true, "moduleResolution": "bundler", "allowImportingTsExtensions": true, @@ -20,6 +21,6 @@ "@/*": ["src/*"] } }, - "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"], + "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "vite-env.d.ts"], "references": [{ "path": "./tsconfig.node.json" }] } diff --git a/frontend/vite-env.d.ts b/frontend/vite-env.d.ts new file mode 100644 index 0000000..0f63c22 --- /dev/null +++ b/frontend/vite-env.d.ts @@ -0,0 +1,11 @@ +/// + +interface ImportMetaEnv { + readonly VITE_JINGROW_SERVER_URL: string + readonly VITE_BACKEND_SERVER_URL: string + // 更多环境变量... +} + +interface ImportMeta { + readonly env: ImportMetaEnv +} diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index eb70e7a..fc80c35 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -17,7 +17,7 @@ export default defineConfig({ resolvers: [ IconsResolver({ prefix: 'i', - enabledCollections: ['tabler'] // 只启用Tabler图标 + enabledCollections: ['tabler'] }), ], }),