Merged
Conversation
Updated iframe source URLs to use the window's hostname instead of localhost.本次提交解决了局域网内其他设备无法正常访问后端服务的问题。此前前端代码中硬编码了localhost作为后端服务的主机地址,导致其他设备访问时,localhost会指向设备自身而非实际运行服务的主机,从而无法连接后端。 主要修改内容: 将前端中硬编码的localhost替换为window.location.hostname,动态获取当前页面的主机 IP(即运行服务的电脑局域网 IP)。 涉及修改的关键位置: preloadIframes函数:预加载 iframe 时,使用动态主机地址生成后端服务 URL(如http://${window.location.hostname}:8501)。 performSearch函数:发送搜索请求时,同样使用动态主机地址构建请求 URL,确保后端接口调用正确指向服务主机。 注意事项: 为确保局域网访问正常,后端服务(运行在 8501、8502、8503 等端口)需配置为绑定到0.0.0.0(而非默认的localhost),以允许来自局域网的连接。例如,Python 服务可通过app.run(host='0.0.0.0', port=8501)启动。 效果: 修改后,局域网内其他设备通过服务主机的局域网 IP(如192.168.1.100)访问前端页面时,可自动正确连接到后端服务,实现跨设备正常使用。 Contributor Author
| 提了一个PR,解决这个局域网内其他服务器访问的问题 |
|
Owner
| 好的,今晚我回去测试一下,没问题就可以合并了,感谢兄弟 |
Contributor Author
客气了,解决了自己的问题也要让大家都避免同样的错误 |
Owner
| 经过测试没有问题,已经合并到主分支了😘 |
This file contains hidden or 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Updated iframe source URLs to use the window's hostname instead of localhost.本次提交解决了局域网内其他设备无法正常访问后端服务的问题。此前前端代码中硬编码了localhost作为后端服务的主机地址,导致其他设备访问时,localhost会指向设备自身而非实际运行服务的主机,从而无法连接后端。 主要修改内容:
将前端中硬编码的localhost替换为window.location.hostname,动态获取当前页面的主机 IP(即运行服务的电脑局域网 IP)。 涉及修改的关键位置:
preloadIframes函数:预加载 iframe 时,使用动态主机地址生成后端服务 URL(如http://${window.location.hostname}:8501)。 performSearch函数:发送搜索请求时,同样使用动态主机地址构建请求 URL,确保后端接口调用正确指向服务主机。 注意事项:
为确保局域网访问正常,后端服务(运行在 8501、8502、8503 等端口)需配置为绑定到0.0.0.0(而非默认的localhost),以允许来自局域网的连接。例如,Python 服务可通过app.run(host='0.0.0.0', port=8501)启动。 效果:
修改后,局域网内其他设备通过服务主机的局域网 IP(如192.168.1.100)访问前端页面时,可自动正确连接到后端服务,实现跨设备正常使用。