Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

再开:没法打开/关闭地图按钮的问题 #171

Closed
dreamsmaner opened this issue Apr 12, 2024 · 6 comments
Closed

再开:没法打开/关闭地图按钮的问题 #171

dreamsmaner opened this issue Apr 12, 2024 · 6 comments

Comments

@dreamsmaner
Copy link

作者你好,还是前几天那个没法打开/关闭地图按钮的问题,那个issue被你close了,但其实变量名我设置应该是对的,问题没解决。

          > 变量名是 BING_MAP_API_KEY 。

Docker里是写的BING_MAP_API_KEY,上面issue的描述没打全,看图。
image

Originally posted by @dreamsmaner in #161 (comment)

@dreamsmaner dreamsmaner changed the title > 变量名是 BING_MAP_API_KEY 。 再开:没法打开/关闭地图按钮的问题 Apr 12, 2024
@jason5ng32
Copy link
Owner

帮不了你,程序是没问题的。我也通过 docker run 部署了一次,一切正常。建议部署后进入容器里看看环境变量是不是确实已经进去了。再不行,结合你的环境,问问 ChatGPT。

@Jeamorg
Copy link
Contributor

Jeamorg commented Apr 13, 2024

BING_MAP_API_KEY 的值没有 ""

@dreamsmaner
Copy link
Author

BING_MAP_API_KEY 的值没有 ""

加引号和不加引号我都试过了,都不行

@catfishlty
Copy link

catfishlty commented Apr 16, 2024

有同样问题,但是系统变量是成功注入到容器中的。
具体原因是因为/api/configs API会校验ALLOWED_DOMAINS, /api/configs应该是返回了403错误导致前端拿不到正确的参数,所以加上ALLOWED_DOMAINS就好了。

MyIP/api/configs.js

Lines 8 to 18 in 8344159

// 限制只能从指定域名访问
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?' });
}

@jason5ng32
Copy link
Owner

jason5ng32 commented Apr 16, 2024

allowedDomains 默认会加上 localhost ,即使环境变量不存在 ALLOWED_DOMAINS 也不会出错。

不过 @catfishlty 给了我楼主那个问题的思路(以及你也遇到这个问题的原因),我们访问群晖时用的不是 localhost ,而是具体的 IP 或者 DDNS 之后的域名。所以,如果不设置环境变量 ALLOWED_DOMAINS ,按照我的程序逻辑,会判断 API 可能被盗用,于是地图就不会显示。在这种情况下,理论上其它后端的 API 也会报错。

破案了。

@dreamsmaner
Copy link
Author

测试成功,果然ALLOWED_DOMAINS加上群晖的IP就好了,谢谢 @catfishlty@jason5ng32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants