feat: 支持配置泛域名

This commit is contained in:
imsyy
2024-11-05 15:58:22 +08:00
parent d0dfba27dc
commit d27ef0d116
2 changed files with 4 additions and 4 deletions

6
.env
View File

@@ -2,11 +2,11 @@
PORT = 6688 PORT = 6688
# 允许的域名 # 允许的域名
ALLOWED_DOMAIN = "https://api-hot.imsyy.top" ALLOWED_DOMAIN = "*"
# 允许的主域名,填写为 imsyy.top # 允许的主域名,填写格式为 imsyy.top
## 若填写该项,将忽略 ALLOWED_DOMAIN ## 若填写该项,将忽略 ALLOWED_DOMAIN
ALLOWED_HOST = "imsyy.top" ALLOWED_HOST = ""
# ROBOT # ROBOT
DISALLOW_ROBOT = true DISALLOW_ROBOT = true

View File

@@ -30,7 +30,7 @@ app.use(
// 可写为数组 // 可写为数组
origin: (origin) => { origin: (origin) => {
// 是否指定域名 // 是否指定域名
const isSame = origin.endsWith(config.ALLOWED_HOST); const isSame = config.ALLOWED_HOST && origin.endsWith(config.ALLOWED_HOST);
return isSame ? origin : config.ALLOWED_DOMAIN; return isSame ? origin : config.ALLOWED_DOMAIN;
}, },
allowMethods: ["POST", "GET", "OPTIONS"], allowMethods: ["POST", "GET", "OPTIONS"],