forked from jason5ng32/MyIP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request jason5ng32#154 from jason5ng32/dev
Improvements
- Loading branch information
Showing
10 changed files
with
213 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 验证环境变量是否存在,以进行前端功能的开启和关闭 | ||
export default (req, res) => { | ||
// 限制请求方法 | ||
if (req.method !== 'GET') { | ||
return res.status(405).json({ message: 'Method Not Allowed' }); | ||
} | ||
|
||
// 限制只能从指定域名访问 | ||
const allowedDomains = ['localhost', ...(process.env.ALLOWED_DOMAINS || '').split(',')]; | ||
const referer = req.headers.referer; | ||
if (referer) { | ||
const domain = new URL(referer).hostname; | ||
if (!allowedDomains.includes(domain)) { | ||
return res.status(403).json({ error: 'Access denied' }); | ||
} | ||
} else { | ||
return res.status(403).json({ error: 'What are you doing?' }); | ||
} | ||
|
||
const envConfigs = { | ||
bingMap: process.env.BING_MAP_API_KEY, | ||
ipInfo: process.env.IPINFO_API_TOKEN, | ||
ipChecking: process.env.IPChecking_API_KEY, | ||
keyCDN: process.env.KEYCDN_USER_AGENT, | ||
originalSite: req.headers.referer && (new URL(req.headers.referer).hostname === 'ipcheck.ing' || new URL(req.headers.referer).hostname === 'www.ipcheck.ing'), | ||
cloudFlare: process.env.CLOUDFLARE_API, | ||
recaptcha: process.env.VITE_RECAPTCHA_SITE_KEY && process.env.RECAPTCHA_SECRET_KEY | ||
}; | ||
let result = {}; | ||
for (const key in envConfigs) { | ||
result[key] = !!envConfigs[key]; | ||
} | ||
res.status(200).json(result); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.