初始化2

This commit is contained in:
2026-04-08 17:10:58 +08:00
commit 4986d90eb9
532 changed files with 112617 additions and 0 deletions

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)
}
})
})