3

I want to follow the instruction :https://strapi.io/blog/building-a-static-website-using-gatsby-and-strapi#allowaccess

But encounter Error: Request failed with status code 404

Node.js version: v10.13.0 npm version: 6.14.6 Strapi version: 3.1.0-alpha.5 Operating system: mac

Which example is causing problem? strapi.io/blog/building-a-static-website-using-gatsby-and-strapi#allowaccess

What is the current behavior? Graphql Query doesn't work.

the steps to reproduce the problem:

$ 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

What is the expected behavior? What is the expected behavior?

Doesn't work when I try to get from gatsby http://localhost:8000/___graphql

There is no method allStrapiblogs on http://localhost:8000/___graphql

Gloria1009
  • 61
  • 1
  • 6

4 Answers4

1

Please share your gatsby-config.js screen, the gatsby-source-strapi section.

this could be caused by the collectionTypes/singleTypes in the gatsby-source-strapi, or your USERS & PERMISSIONS PLUGIN (roles) in strapi is not set

Prosper Atu
  • 41
  • 1
  • 1
  • 1
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/29789565) – Paulo Sep 10 '21 at 11:16
1

I've changed contentTypes to collectionTypes

Also there is a new version (v4) of strapi and to make gatsby work with this new version, you need to use the following gatsby-source plugin.

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

This plugin wants a token which you can create at http://localhost:1337/admin/settings/api-tokens

before testing the new plugin make sure to clean out your gatsby cache by using the following command: 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: {},
  },
},

There has also been a article about a new plugin, but this refers to another one which didn't work for me. https://strapi.io/blog/introducing-the-new-gatsby-source-strapi-plugin

Luhn
  • 706
  • 6
  • 15
  • Excellent, 2 days looking for a solution, this plugin works, the others in the gatsby docs dont work with images in V4 – Gaston Fassi Lavalle Jan 23 '22 at 16:49
  • I must add that for some reason the plugin won't work in production mode for me. Don't know if this is the case for everyone. – Luhn Jan 24 '22 at 10:31
  • It works fine for me, gatsby-config.js { resolve: 'gatsby-source-strapi', options: { apiURL: 'http://localhost:1337', collectionTypes: ['paginas'], singleTypes: ['principal',"servicio"], // Extract images from markdown fields. // markdownImages: { // typesToParse: { // Article: ['body'], // ComponentBlockBody: ['text'], // }, // }, // Only include specific locale. locale: 'es', preview: false, token: 'xx', }, }, – Gaston Fassi Lavalle Jan 25 '22 at 19:55
0

When added "${DOMAIN}/api" on apiURL it worked for me with 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: {},
  },
},
-1

This code solved my problem.

{
  resolve:'gatsby-source-strapi',
  options:{
      apiURL:'*http://localhost:1337/admin/content-manager/collectionType/api::*',
     
      collectionTypes: ['propiedads','paginas','categorias'],
      queryLimit:1000
    }
}
cigien
  • 57,834
  • 11
  • 73
  • 112
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 23 '21 at 23:10
  • This failed for me, same error – Blissful Jan 05 '22 at 00:06