删除文件中的VITE_JINGROW_SERVER_URL,统一用vite转发实现

This commit is contained in:
jingrow 2025-11-03 23:06:26 +08:00
parent 3a5e8340ce
commit d27cb3d4ca
6 changed files with 25 additions and 31 deletions

View File

@ -6,8 +6,7 @@ import { deleteRecords, createRecord, updateRecord, getFieldSelectOptions, getRe
// 重新导出类型,供其他模块使用
export type { AIAgent, AgentExecutionResult }
// 使用相对路径通过Vite代理转发到后端
const jingrowServerUrl = import.meta.env.VITE_JINGROW_SERVER_URL || ''
// 统一使用相对路径,通过 Vite 代理转发到后端
// 获取Jingrow API鉴权头部
function get_jingrow_api_headers() {
@ -31,7 +30,7 @@ function get_jingrow_api_headers() {
// 获取AI Agent列表
export const getAgentsApi = async (): Promise<AIAgent[]> => {
try {
const url = `${jingrowServerUrl}/api/action/jingrow.ai.utils.jlocal.get_local_ai_agents_list`
const url = `/api/action/jingrow.ai.utils.jlocal.get_local_ai_agents_list`
const requestData = {
filters: [],
@ -84,7 +83,7 @@ export const getAgentDetail = async (name: string): Promise<AIAgent> => {
export const executeAgentApi = async (name: string): Promise<{ success: boolean; message?: string }> => {
try {
const response = await axios.post(
`${jingrowServerUrl}/api/action/jingrow.ai.utils.jlocal.execute_local_ai_agent`,
`/api/action/jingrow.ai.utils.jlocal.execute_local_ai_agent`,
{
name: name
},
@ -117,7 +116,7 @@ export const executeAgentApi = async (name: string): Promise<{ success: boolean;
export const updateAgentApi = async (name: string, data: Partial<AIAgent>): Promise<AIAgent> => {
try {
const response = await axios.post(
`${jingrowServerUrl}/api/action/jingrow.ai.utils.jlocal.update_local_ai_agent`,
`/api/action/jingrow.ai.utils.jlocal.update_local_ai_agent`,
{
name: name,
data: data

View File

@ -1,5 +1,3 @@
const jingrowServerUrl = import.meta.env.VITE_JINGROW_SERVER_URL || ''
export interface LoginResponse {
message: string
user: UserInfo
@ -30,7 +28,7 @@ export function getSessionCookie(): string | null {
}
export const loginApi = async (username: string, password: string): Promise<LoginResponse> => {
const response = await fetch(`${jingrowServerUrl}/api/action/login`, {
const response = await fetch(`/api/action/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
@ -60,7 +58,7 @@ export const loginApi = async (username: string, password: string): Promise<Logi
// 获取用户信息
export const getUserInfoApi = async (): Promise<UserInfo> => {
const response = await fetch(`${jingrowServerUrl}/api/action/jingrow.realtime.get_user_info`, {
const response = await fetch(`/api/action/jingrow.realtime.get_user_info`, {
method: 'GET',
headers: {
'Accept': 'application/json',
@ -89,7 +87,7 @@ export const getUserInfoApi = async (): Promise<UserInfo> => {
// 登出
export const logoutApi = async (): Promise<void> => {
await fetch(`${jingrowServerUrl}/api/action/logout`, {
await fetch(`/api/action/logout`, {
method: 'GET',
headers: { 'Accept': 'application/json' },
credentials: 'include'

View File

@ -1,7 +1,7 @@
import axios from 'axios'
import { get_session_api_headers } from './auth'
const jingrowServerUrl = import.meta.env.VITE_JINGROW_SERVER_URL || ''
// 统一使用相对路径,通过 Vite 代理转发到后端
// 删除记录的通用函数
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(
`${jingrowServerUrl}/api/action/jingrow.client.delete`,
`/api/action/jingrow.client.delete`,
{
pagetype: pagetype,
name: name
@ -134,7 +134,7 @@ export const uploadAttachment = async (
formData.append('folder', 'Home')
const response = await axios.post(
`${jingrowServerUrl}/api/action/upload_file`,
`/api/action/upload_file`,
formData,
{
headers: {
@ -179,7 +179,7 @@ export const getWorkspace = async (name: string): Promise<{ success: boolean; da
export const getCount = async (pagetype: string): Promise<{ success: boolean; count?: number; message?: string }> => {
try {
const response = await axios.get(
`${jingrowServerUrl}/api/action/jingrow.client.get_count`,
`/api/action/jingrow.client.get_count`,
{
params: {
pagetype: pagetype
@ -204,7 +204,7 @@ export const getCount = async (pagetype: string): Promise<{ success: boolean; co
export const getLocalJobCount = async (): Promise<{ success: boolean; count?: number; message?: string }> => {
try {
const response = await axios.get(
`${jingrowServerUrl}/api/action/jingrow.core.pagetype.local_job.local_job.get_local_job_count`,
`/api/action/jingrow.core.pagetype.local_job.local_job.get_local_job_count`,
{
headers: get_session_api_headers(),
withCredentials: true
@ -267,7 +267,7 @@ export const getRecords = async (pagetype: string, filters: any[] = [], fields:
export const getFieldSelectOptions = async (pagetype: string, fieldname: string): Promise<string[]> => {
try {
const res = await axios.post(
`${jingrowServerUrl}/api/action/jingrow.ai.utils.utils.get_field_select_options`,
`/api/action/jingrow.ai.utils.utils.get_field_select_options`,
{ pagetype, fieldname },
{ headers: get_session_api_headers(), withCredentials: true }
)
@ -339,7 +339,7 @@ export const uploadFileToJingrow = async (
}
const response = await axios.post(
`${jingrowServerUrl}/api/action/upload_file`,
`/api/action/upload_file`,
formData,
{
headers: {

View File

@ -2,7 +2,7 @@ import axios from 'axios'
import { get_session_api_headers } from './auth'
import { deleteRecords, createRecord, getFieldSelectOptions } from './common'
const jingrowServerUrl = import.meta.env.VITE_JINGROW_SERVER_URL || ''
// 统一使用相对路径,通过 Vite 代理转发到后端
// 使用通用函数,这里可以保留别名或直接使用
export { getFieldSelectOptions as getNodeFieldSelectOptions } from './common'
@ -16,7 +16,7 @@ export const checkNodeTypeExists = async (nodeType: string): Promise<boolean> =>
if (!nodeType) return false
try {
const response = await axios.post(
`${jingrowServerUrl}/api/action/jingrow.ai.utils.jlocal.check_node_type_exists`,
`/api/action/jingrow.ai.utils.jlocal.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<any> => {
try {
const response = await axios.get(
`${jingrowServerUrl}/api/action/jingrow.ai.utils.jlocal.get_node_record`,
`/api/action/jingrow.ai.utils.jlocal.get_node_record`,
{
params: { name },
headers: get_session_api_headers(),
@ -59,7 +59,7 @@ export const getNodeRecord = async (name: string): Promise<any> => {
export const updateNode = async (name: string, nodeData: any): Promise<any> => {
try {
const response = await axios.post(
`${jingrowServerUrl}/api/action/jingrow.ai.utils.jlocal.update_node`,
`/api/action/jingrow.ai.utils.jlocal.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<any> => {
export const getNodeByType = async (nodeType: string): Promise<any> => {
try {
const response = await axios.post(
`${jingrowServerUrl}/api/action/jingrow.ai.utils.jlocal.get_node_by_type`,
`/api/action/jingrow.ai.utils.jlocal.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<any> => {
export const getNodeSchemaFields = async (nodeType: string): Promise<any[]> => {
try {
const response = await axios.post(
`${jingrowServerUrl}/api/action/jingrow.ai.utils.jlocal.get_node_schema_fields`,
`/api/action/jingrow.ai.utils.jlocal.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(
`${jingrowServerUrl}/api/action/jingrow.ai.utils.jlocal.get_node_list?${params}`,
`/api/action/jingrow.ai.utils.jlocal.get_node_list?${params}`,
{ headers: get_session_api_headers(), withCredentials: true }
)
return response.data?.message || response.data

View File

@ -150,8 +150,7 @@ async function onDropdownShow(shown: boolean) {
if (!shown || pagetypeOptions.value.length) return
loading.value = true
try {
const base = (import.meta as any).env.VITE_JINGROW_SERVER_URL || ''
const res = await axios.get(`${base}/api/data/PageType`, { params: { order_by: 'modified desc', limit_page_length: 1000 }, headers: get_session_api_headers(), withCredentials: true })
const res = await axios.get(`/api/data/PageType`, { params: { order_by: 'modified desc', limit_page_length: 1000 }, headers: get_session_api_headers(), withCredentials: true })
const list = res.data?.data || []
pagetypeOptions.value = list.map((x: any) => ({ label: x.name, value: x.name }))
} catch (e: any) {
@ -190,8 +189,7 @@ async function onPagetypeChange() {
moduleName.value = ''
if (!form.value.pagetype) return
try {
const base = (import.meta as any).env.VITE_JINGROW_SERVER_URL || ''
const res = await axios.get(`${base}/api/action/jingrow.ai.utils.jlocal.get_pagetype_module_app`, {
const res = await axios.get(`/api/action/jingrow.ai.utils.jlocal.get_pagetype_module_app`, {
params: { pagetype: form.value.pagetype },
headers: get_session_api_headers(),
withCredentials: true
@ -211,8 +209,7 @@ async function handleSubmit() {
if (errors) return
submitting.value = true
try {
const base = (import.meta as any).env.VITE_JINGROW_SERVER_URL || ''
const res = await axios.post(`${base}/jingrow/dev/create-pagetype-template`, {
const res = await axios.post(`/jingrow/dev/create-pagetype-template`, {
pagetype: form.value.pagetype,
app: appName.value,
module: moduleName.value,

View File

@ -62,7 +62,7 @@ export default defineConfig({
},
proxy: {
'/api/action': {
target: process.env.VITE_JINGROW_SERVER_URL || 'http://192.168.2.58',
target: process.env.VITE_JINGROW_SERVER_URL || 'https://simon.c1.site.jingrow.com',
changeOrigin: true,
secure: false
},