使用 GitHub 页面部署后未找到资源
Resources not found after deploying with GitHub pages
我已经 fork this 存储库,然后按照建议继续构建和部署它,但我无法正确启动该网站。
我关注的通行证是:
- git 克隆了 repo
- 移动到文件夹中并执行没有任何问题:
npm install -g yarn
- 已执行:
yarn
- 已执行:
npm install -g gatsby-cli
- 已执行:
npm install
- 已执行:
gatsby build
- 已执行:
npm run deploy
其中部署定义为:gatsby build && gh-pages -d public -b gh-pages
这些命令正确地构建了项目并在存储库中创建了一个新分支,其中包含 public 文件夹,即构建文件夹。
我的存储库配置为使用 GitHub 页面,如下所示:
但是每当我打开网站时,我只能看到背景颜色和打开控制台,我看到访问资源时出现一些错误:
Failed to load resource: the server responded with a status of 404 ()
webpack-runtime-b79041fc2b38a6c91c6b.js:1
Failed to load resource: the server responded with a status of 404 ()
app-8f8fb0f08c61a13c61ac.js:1
[...]
我可以正确地更改存储库并使用 gatsby serve
在本地启动它。我遇到的唯一问题是部署,有人可以找出我提供的信息有什么问题吗?
您的 GitHub 页面站点发布在 https://surveiior.github.io/surveiior.com/
而不是 https://surveiior.github.io/
。
因此,例如,
您在HTML代码中使用了/page-data/index/page-data.json
,它将请求发送到https://surveiior.github.io/page-data/index/page-data.json
, but the json
file is published at https://surveiior.github.io/surveiior.com/page-data/index/page-data.json
。
您可以在 HTML 代码中使用 ./page-data/index/page-data.json
或 page-data/index/page-data.json
,它是托管文件的位置。
简而言之,使文件路径正确,你可以在每个显示错误404的地址的斜杠前加一个.
[点],如果文件路径正确,它会显示正确的文件。
我已经 fork this 存储库,然后按照建议继续构建和部署它,但我无法正确启动该网站。
我关注的通行证是:
- git 克隆了 repo
- 移动到文件夹中并执行没有任何问题:
npm install -g yarn
- 已执行:
yarn
- 已执行:
npm install -g gatsby-cli
- 已执行:
npm install
- 已执行:
gatsby build
- 已执行:
npm run deploy
其中部署定义为:gatsby build && gh-pages -d public -b gh-pages
这些命令正确地构建了项目并在存储库中创建了一个新分支,其中包含 public 文件夹,即构建文件夹。
我的存储库配置为使用 GitHub 页面,如下所示:
但是每当我打开网站时,我只能看到背景颜色和打开控制台,我看到访问资源时出现一些错误:
Failed to load resource: the server responded with a status of 404 ()
webpack-runtime-b79041fc2b38a6c91c6b.js:1
Failed to load resource: the server responded with a status of 404 ()
app-8f8fb0f08c61a13c61ac.js:1
[...]
我可以正确地更改存储库并使用 gatsby serve
在本地启动它。我遇到的唯一问题是部署,有人可以找出我提供的信息有什么问题吗?
您的 GitHub 页面站点发布在 https://surveiior.github.io/surveiior.com/
而不是 https://surveiior.github.io/
。
因此,例如,
您在HTML代码中使用了/page-data/index/page-data.json
,它将请求发送到https://surveiior.github.io/page-data/index/page-data.json
, but the json
file is published at https://surveiior.github.io/surveiior.com/page-data/index/page-data.json
。
您可以在 HTML 代码中使用 ./page-data/index/page-data.json
或 page-data/index/page-data.json
,它是托管文件的位置。
简而言之,使文件路径正确,你可以在每个显示错误404的地址的斜杠前加一个.
[点],如果文件路径正确,它会显示正确的文件。