首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >(Gatsby-Strapi)错误:请求失败,状态代码为404

(Gatsby-Strapi)错误:请求失败,状态代码为404
EN

Stack Overflow用户
提问于 2020-08-02 14:10:05
回答 4查看 913关注 0票数 2

我想要遵循以下说明:https://strapi.io/blog/building-a-static-website-using-gatsby-and-strapi#allowaccess

但遇到错误:请求失败,状态代码为404

Node.js版本:v10.13.0npm版本:6.14.6strapi版本: 3.1.0-alpha.5操作系统: mac

哪个示例导致了问题?strapi.io/blog/building-a-static-website-using-gatsby-and-strapi#allowaccess

当前的行为是什么?Graphql查询不起作用。

重现问题的步骤:

代码语言:javascript
复制
$ gatsby develop
success open and validate gatsby-configs
success load plugins - 2.011s
success onPreInit - 0.004s
success initialize cache - 0.018s
success copy gatsby files - 0.102s
success onPreBootstrap - 0.017s
success createSchemaCustomization -
info Starting to fetch data from Strapi
info Starting to fetch data from Strapi
info Starting to fetch data from Strapi

ERROR #11321 PLUGIN

"gatsby-source-strapi" threw an error while running the sourceNodes lifecycle:

Request failed with status code 404

Error: Request failed with status code 404

createError.js:16 createError
[portfolio_v4]/[gatsby-source-strapi ]/[axios]/lib/core/createError.js:16 :15

settle.js:18 settle
[portfolio_v4]/[gatsby-source-strapi ]/[axios]/lib/core/settle.js:18:12

http.js:202 IncomingMessage.handleSt reamEnd
[portfolio_v4]/[gatsby-source-strapi ]/[axios]/lib/adapters/http.js:202:1 1

task_queues.js:84 processTicksAndRej ections
internal/process/task_queues.js:84:2 1

预期的行为是什么?预期的行为是什么?

当我尝试从gatsby http://localhost:8000/___graphql获取时不起作用

http://localhost:8000/___graphql上没有allStrapiblogs方法

EN

回答 4

Stack Overflow用户

发布于 2021-09-10 08:33:29

请分享您的gatsby-config.js屏幕,gatsby-source-strapi部分。

这可能是由gatsby-source-strapi中的集合类型/singleTypes或未设置strapi中的用户和权限插件(角色)造成的

票数 1
EN

Stack Overflow用户

发布于 2022-01-17 16:46:15

我已将contentTypes更改为collectionTypes

还有一个新的盖茨比版本( version,v4)strapi,要让它与这个新版本一起工作,您需要使用以下gatsby-source插件。

代码语言:javascript
复制
npm install --save gatsby-source-strapi@relate-app/gatsby-source-strapi

此插件需要一个令牌,您可以在http://localhost:1337/admin/settings/api-tokens创建该令牌

在测试新插件之前,请确保使用以下命令清理gatsby缓存:gatsby clean

代码语言:javascript
复制
{
  resolve: "gatsby-source-strapi",
  options: {
    apiURL: "http://localhost:1337",
    collectionTypes: ["Article", "User", 'Test'],
    // Extract images from markdown fields.
    markdownImages: {
      typesToParse: {
        Article: ["body"],
        ComponentBlockBody: ["text"],
      },
    },
    // Only include specific locale.
    locale: "en", // default to all
    // Include drafts in build.
    preview: true, // defaults to false
    // Use application token.
    token:
      'Your-strapi-api-token',
    // Add additional headers.
    headers: {},
  },
},

也有一篇关于一个新插件的文章,但这篇文章提到了另一个不适用于我的插件。https://strapi.io/blog/introducing-the-new-gatsby-source-strapi-plugin

票数 1
EN

Stack Overflow用户

发布于 2022-02-11 06:10:24

当在apiURL上添加"${DOMAIN}/api“时,它适用于我的strapi v4

apiURL:"http://localhost:1337/api"

代码语言:javascript
复制
{
  resolve: "gatsby-source-strapi",
  options: {
    apiURL: "http://localhost:1337/api",
    collectionTypes: [`messages`],
    // Extract images from markdown fields.
    markdownImages: {
      typesToParse: {
        Article: ["body"],
        ComponentBlockBody: ["text"],
      },
    },
    // Only include specific locale.
    locale: "en", // default to all
    // Include drafts in build.
    preview: true, // defaults to false
    // Use application token.
    token: "token",
    // Add additional headers.
    headers: {},
  },
},
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63212938

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档