将应用程序部署到 Heroku 后无法调用 API

章鱼

我制作了一个天气应用程序,它通过 API 调用 freegeoip 来定位您当前位置的坐标,然后使用这些坐标连接到 openweathermap API 以获取您当前位置的天气。

在开发中,该应用程序运行良好。但是在部署到 Heroku 之后,我似乎得到了一个 CORS 错误?

控制台日志:

Mixed Content: The page at 'https://weather-react-drhectapus.herokuapp.com/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://freegeoip.net/json/'. This request has been blocked; the content must be served over HTTPS.

链接到Heroku 应用程序

编辑:

更改为https似乎适用于 freegeoip API ( https://freegeoip.net/json/),但不适用于 openweathermap API。这是我得到的完整控制台日志:

GET https://api.openweathermap.org/data/2.5/weather?appid=95108d63b7f0cf597d80c6d17c8010e0&lat=49.25&lon=4.0333 net::ERR_CONNECTION_CLOSED

bundle.js:16 Uncaught (in promise) Error: Network Error
    at e.exports (bundle.js:16)
    at XMLHttpRequest.d.onerror (bundle.js:16)

Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys

Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error
安德烈科

只需将 API 端点更改为使用https而不是http.

https://freegeoip.net/json/ 效果很好 ;)

更新
您更新的问题还包含一个请求。不幸的是,api.openweathermap.org无法通过 HTTPS 使用。因此,您需要在您的控制下通过代理访问它并将响应转发给您的客户端。有关更多信息,请参阅此答案

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

部署到 Heroku 后,节点应用程序无法命中 API。它说 err::Connection Refused

无法将Spring Boot应用程序部署到heroku

无法将示例GOLang应用程序部署到Heroku

无法将 Laravel 应用程序部署到 Heroku

无法将应用程序部署到heroku

无法将 rails 应用程序部署到 heroku

无法使用 heroku local 将 Django 应用程序部署到 heroku

将MERN应用程序部署到Heroku后,缺少React组件

无法将Django应用程序部署到Heroku“未检测到Cedar支持的应用程序”

将AngularJS应用程序部署到Heroku,无法找到合适的角度动画版本

如果与DefinePlugin一起使用,则无法将应用程序部署到Heroku

将 sinatra 应用程序部署到 heroku 的神秘错误:bundler:无法加载命令:rackup

尝试将Django应用程序部署到Heroku时出现“无法连接('0.0.0.0',5000)”

将Rails应用程序部署到Heroku时出现“无法加载此类文件”错误

无法使用 django-allauth 将 django 应用程序部署到 heroku

无法将我的 symfony 应用程序部署到 heroku

我的应用程序无法部署到 heroku

jhipster-将应用程序部署到Heroku后无法运行本地开发人员配置文件

Heroku Twitter API应用程序部署

无法将Flask应用程序部署到Heroku(Heroku尝试安装SQlite,即使我根本不使用它)

将应用程序部署到Heroku时,对Rails API后端和React前端的身份验证请求失败

将应用程序部署到Heroku之后,API_URL配置变量以当前应用程序的URL开头,从而导致请求URL错误

使用git push将Django应用程序部署到heroku时出现无法识别的错误

由于硬编码的端口号,无法将node.js应用程序部署到heroku

MERN应用程序在部署到Heroku时无法运行“ heroku-postbuild”脚本

Vue Cli应用程序无法部署到heroku“错误:无法解析vue-axios”

成功构建 rails 应用程序并将其部署到 heroku 后出现 NPM 错误

将Angular应用程序部署到Heroku时出错

将烧瓶应用程序部署到 heroku 错误