feat: 新增CWD评论系统前后端代码及文档
refactor: 移除旧版评论系统代码并重构为Vue3前端 docs: 更新后端配置文档说明 fix: 修复评论提交频率限制和邮件通知逻辑 style: 格式化代码并优化样式 test: 添加Vitest测试配置 build: 更新依赖项和构建配置 chore: 清理无用文件和缓存
This commit is contained in:
23
cwd-comments-api/src/utils/cors.ts
Normal file
23
cwd-comments-api/src/utils/cors.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { cors } from 'hono/cors'
|
||||
|
||||
export const customCors = (allowOriginStr: string | undefined) => {
|
||||
// 1. 将环境变量字符串解析为数组
|
||||
// 如果环境变量不存在,则默认为空数组
|
||||
const allowedOrigins = allowOriginStr
|
||||
? allowOriginStr.split(',').map(origin => origin.trim())
|
||||
: []
|
||||
|
||||
return cors({
|
||||
origin: (origin) => {
|
||||
// 如果请求的 origin 在白名单中,或者是本地文件(null)
|
||||
if (!origin || allowedOrigins.includes(origin)) {
|
||||
return origin
|
||||
}
|
||||
},
|
||||
allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||
allowHeaders: ['Content-Type', 'Authorization'],
|
||||
exposeHeaders: ['Content-Length'],
|
||||
maxAge: 600,
|
||||
credentials: true,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user