reactjs - React 应用程序在本地正常运行,但在 Github 页面上不正常
问题描述
我将我的一页 React 项目推送到 github 页面。当页面出现时,它不能正常工作。这是一个基本的应用程序,用户通过 API 进行搜索,然后当他们点击一部电影时,它就会被添加到他们的观看列表中。但是,当我通过搜索输入查询时,与出现电影且一切正常的本地主机相比,什么都没有发生。
当我通过控制台检查它时,我收到以下错误:'' 处的页面是通过 HTTPS 加载的,但请求了一个不安全的资源 ''。此请求已被阻止;内容必须通过 HTTPS 提供。
这是我的 package.json
{
"name": "watchlater",
"homepage": "https://myusername.github.io/watchlater/",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"bootstrap": "^4.5.3",
"gh-pages": "^3.1.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.0",
"web-vitals": "^0.2.4"
},
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
还有什么我需要改变的吗?我按照此处的说明(https://create-react-app.dev/docs/deployment)将其发布在 gh-pages 上,但实际功能不起作用。
解决方案
这个错误被称为“混合内容” 您正试图通过“HTTPS”站点上的“HTTP”访问,因为这容易受到黑客的窃听攻击,这是一种违规行为。
推荐阅读
- maven - 目标执行默认 com.smartbear.soapui:soapui-maven-plugin:4.6.1:test failed
- javascript - 从 JQuery 中的值切换时,不要在更改时再次加载 div
- excel - 在 Excel VBA 中使用 XMLHTTPRequest 时,我无法解析未定义的用户定义类型
- html - Autocomplete="off" 在 chrome 版本 75.0.3770.142 中不起作用
- typescript - 类型为对象键的字符串路径
- android-gradle-plugin - 如何修复在根项目“myProject”中找不到任务“$”
- objective-c - NSAttributedString 到 HTML,NSOBliquenessAttributeName 无法转换
- django - 在使用 reverse 进行重定向时,传递可选的 kwargs 会导致 url 始终保留参数
- ionic-framework - 应用程序中的离子加载 URL 不在应用程序浏览器中
- c++ - 如何从外部将值传递给结构函数?