2

我想按照说明操作:https ://strapi.io/blog/building-a-static-website-using-gatsby-and-strapi#allowaccess

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

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

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

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

重现问题的步骤:

$ 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

4

4 回答 4

1

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

这可能是由 中的collectionTypes/singleTypes 引起的gatsby-source-strapi,或者您未设置strapi 中的USERS & PERMISSIONS PLUGIN (roles)

于 2021-09-10T08:33:28.600 回答
1

我已经contentTypes 改为collectionTypes

还有一个新版本(v4)strapi,要让 gatsby 使用这个新版本,您需要使用以下gatsby-source插件。

npm install --save gatsby-source-strapi@relate-app/gatsby-source-strapi

这个插件需要一个你可以在http://localhost:1337/admin/settings/api-tokens创建的令牌

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

{
  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

于 2022-01-17T16:46:14.550 回答
0

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

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

{
  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: {},
  },
},
于 2022-02-11T06:10:23.757 回答
-1

这段代码解决了我的问题。

{
  resolve:'gatsby-source-strapi',
  options:{
      apiURL:'*http://localhost:1337/admin/content-manager/collectionType/api::*',
     
      collectionTypes: ['propiedads','paginas','categorias'],
      queryLimit:1000
    }
}
于 2021-12-23T20:55:21.087 回答