初始版本

This commit is contained in:
2026-04-23 16:30:57 +08:00
commit 0d0683a6e6
538 changed files with 113042 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
import { defineEventHandler, getHeader, getRequestURL, getRouterParam, proxyRequest, getCookie } from 'h3'
import { useRuntimeConfig } from '#imports'
function joinURL(base: string, path: string) {
if (!path) return base
return base.replace(/\/+$/, '') + '/' + path.replace(/^\/+/, '')
}
export default defineEventHandler((event) => {
const config = useRuntimeConfig()
// 从 Cookie 读取环境设置,优先于环境变量
const envCookie = getCookie(event, 'websopy_api_env')
const isDevEnv = envCookie === 'dev'
// 开发环境使用本地 9500 端口,生产环境使用配置的环境变量
const appApiBase = isDevEnv
? 'http://127.0.0.1:9500'
: (config.public.appApiBase || 'https://websopy-api.websoft.top')
const path = getRouterParam(event, 'path') || ''
const search = getRequestURL(event).search
const target = joinURL(appApiBase + '/api/app', path) + search
const tenantId = getHeader(event, 'tenantid') || config.public.tenantId
const authorization = getHeader(event, 'authorization')
return proxyRequest(event, target, {
headers: {
TenantId: String(tenantId),
...(authorization ? { Authorization: String(authorization) } : {})
}
})
})

View File

@@ -0,0 +1,25 @@
import { defineEventHandler, getHeader, getRequestURL, getRouterParam, proxyRequest } from 'h3'
import { useRuntimeConfig } from '#imports'
function joinURL(base: string, path: string) {
if (!path) return base
return base.replace(/\/+$/, '') + '/' + path.replace(/^\/+/, '')
}
export default defineEventHandler((event) => {
const config = useRuntimeConfig()
const fileServerBase = config.public.fileServerBase || 'https://server.websoft.top'
const path = getRouterParam(event, 'path') || ''
const search = getRequestURL(event).search
const target = joinURL(fileServerBase, path) + search
const tenantId = getHeader(event, 'tenantid') || config.public.tenantId
const authorization = getHeader(event, 'authorization')
return proxyRequest(event, target, {
headers: {
TenantId: String(tenantId),
...(authorization ? { Authorization: String(authorization) } : {})
}
})
})

View File

@@ -0,0 +1,34 @@
import { defineEventHandler, getHeader, getRequestURL, getRouterParam, proxyRequest, getCookie } from 'h3'
import { useRuntimeConfig } from '#imports'
function joinURL(base: string, path: string) {
if (!path) return base
return base.replace(/\/+$/, '') + '/' + path.replace(/^\/+/, '')
}
export default defineEventHandler((event) => {
const config = useRuntimeConfig()
// 从 Cookie 读取环境设置,优先于环境变量
const envCookie = getCookie(event, 'websopy_api_env')
const isDevEnv = envCookie === 'dev'
// 开发环境使用本地 9500 端口,生产环境使用配置的环境变量
const mpApiBase = isDevEnv
? 'http://127.0.0.1:9500'
: (config.public.mpApiBase || 'https://mp-api.websoft.top')
const path = getRouterParam(event, 'path') || ''
const search = getRequestURL(event).search
const target = joinURL(mpApiBase, path) + search
const tenantId = getHeader(event, 'tenantid') || config.public.tenantId
const authorization = getHeader(event, 'authorization')
return proxyRequest(event, target, {
headers: {
TenantId: String(tenantId),
...(authorization ? { Authorization: String(authorization) } : {})
}
})
})

View File

@@ -0,0 +1,34 @@
import { defineEventHandler, getHeader, getRequestURL, getRouterParam, proxyRequest, getCookie } from 'h3'
import { useRuntimeConfig } from '#imports'
function joinURL(base: string, path: string) {
if (!path) return base
return base.replace(/\/+$/, '') + '/' + path.replace(/^\/+/, '')
}
export default defineEventHandler((event) => {
const config = useRuntimeConfig()
// 从 Cookie 读取环境设置,优先于环境变量
const envCookie = getCookie(event, 'websopy_api_env')
const isDevEnv = envCookie === 'dev'
// 开发环境使用本地 9500 端口,生产环境使用配置的环境变量
const serverApiBase = isDevEnv
? 'https://server.websoft.top/api'
: (config.public.serverApiBase || config.public.ServerApi || 'https://server.websoft.top/api')
const path = getRouterParam(event, 'path') || ''
const search = getRequestURL(event).search
const target = joinURL(serverApiBase, path) + search
const tenantId = getHeader(event, 'tenantid') || config.public.tenantId
const authorization = getHeader(event, 'authorization')
return proxyRequest(event, target, {
headers: {
TenantId: String(tenantId),
...(authorization ? { Authorization: String(authorization) } : {})
}
})
})

View File

@@ -0,0 +1,27 @@
import { defineEventHandler, getHeader, getRequestURL, getRouterParam, proxyRequest } from 'h3'
import { useRuntimeConfig } from '#imports'
function joinURL(base: string, path: string) {
if (!path) return base
return base.replace(/\/+$/, '') + '/' + path.replace(/^\/+/, '')
}
/**
* 公开 CMS 接口代理
* 将 /api/cms/* 代理到 mp-api无需登录不要求 Authorization
*/
export default defineEventHandler((event) => {
const config = useRuntimeConfig()
const mpApiBase = config.public.mpApiBase || 'https://mp-api.websoft.top'
const path = getRouterParam(event, 'path') || ''
const search = getRequestURL(event).search
const target = joinURL(mpApiBase + '/api/cms', path) + search
const tenantId = getHeader(event, 'tenantid') || config.public.tenantId
return proxyRequest(event, target, {
headers: {
TenantId: String(tenantId)
}
})
})

View File

@@ -0,0 +1,33 @@
import { $fetch } from 'ofetch'
import { createError, defineEventHandler, getHeader, getQuery } from 'h3'
import { useRuntimeConfig } from '#imports'
export default defineEventHandler(async (event) => {
const config = useRuntimeConfig()
const query = getQuery(event)
const modulesApiBase =
config.public.modulesApiBase || config.public.ApiBase || 'https://websopy-api.websoft.top/api'
const tenantId =
getHeader(event, 'tenantid') ||
config.public.tenantId ||
config.public.TenantId ||
'5'
const authorization = getHeader(event, 'authorization')
try {
return await $fetch('/cms/cms-website/getSiteInfo', {
baseURL: modulesApiBase,
headers: {
TenantId: String(tenantId),
...(authorization ? { Authorization: String(authorization) } : {})
},
query
})
} catch (error: any) {
throw createError({
statusCode: error?.statusCode || error?.response?.status || 502,
statusMessage: error?.statusMessage || 'Failed to fetch site info'
})
}
})

View File

@@ -0,0 +1,33 @@
import { $fetch } from 'ofetch'
import { createError, defineEventHandler, getHeader, getQuery } from 'h3'
import { useRuntimeConfig } from '#imports'
export default defineEventHandler(async (event) => {
const config = useRuntimeConfig()
const query = getQuery(event)
const modulesApiBase =
config.public.modulesApiBase || config.public.ApiBase || 'https://websopy-api.websoft.top/api'
const tenantId =
getHeader(event, 'tenantid') ||
config.public.tenantId ||
config.public.TenantId ||
'5'
const authorization = getHeader(event, 'authorization')
try {
return await $fetch('/cms/cms-website/pageAll', {
baseURL: modulesApiBase,
headers: {
TenantId: String(tenantId),
...(authorization ? { Authorization: String(authorization) } : {})
},
query
})
} catch (error: any) {
throw createError({
statusCode: error?.statusCode || error?.response?.status || 502,
statusMessage: error?.statusMessage || 'Failed to fetch pageAll'
})
}
})