strapi-examples icon indicating copy to clipboard operation
strapi-examples copied to clipboard

Error: Request failed with status code 404

Open chang-you opened this issue 3 years ago • 7 comments

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? https://strapi.io/blog/building-a-static-website-using-gatsby-and-strapi#allowaccess Do you want to request a feature or report a bug? bug What is the current behavior? Graphql Query doesn't work. If the current behavior is a bug, please provide 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.

P.S: authentication has been set public

Clipboard - 2020-08-02 00 27 22

chang-you avatar Aug 02 '20 06:08 chang-you

When I tried to run: npm install --save gatsby-source-strapi

in my project, I also encounter these error:

npm install --save gatsby-source-strapi

> [email protected] install /Users/yoci642/Desktop/portfolio_v4/node_modules/fsevents
> node-gyp rebuild

No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.

gyp: No Xcode or CLT version detected!
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Darwin 19.5.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/yoci642/Desktop/portfolio_v4/node_modules/fsevents
gyp ERR! node -v v12.18.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
npm WARN [email protected] requires a peer of acorn@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of gatsby@^1.9.250 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1`

chang-you avatar Aug 02 '20 06:08 chang-you

Hola, me sucede exactamente lo mismo. Pudieron encontrar una solución ?

1996juli avatar Aug 17 '21 00:08 1996juli

Hi. I had a similar problem:

Failed to fetch data from Strapi Request failed with status code 404

And what I did to fix it was edit the gatsby-config.js, in the part of the plugins. When I'm defining the strapi plugin, you need to define an apiURL, this is always like apiURL: "http://localhost:1337, but this doesn't work to me, so I change it to apiURL: "http://localhost:1337/api. I hope it serves to you 😀

Jofay-zs avatar Jan 06 '22 04:01 Jofay-zs

Oi. Eu tive um problema parecido:

Failed to fetch data from Strapi Request failed with status code 404

E o que fiz para consertar foi editar o gatsby-config.js, na parte dos plugins. Quando estou definindo o plugin strapi, você precisa definir um apiURL, isso é sempre como apiURL: "http://localhost:1337, mas isso não funciona para mim, então eu mudo para apiURL: "http://localhost:1337/api. espero que te sirva😀

Hola amigo! poderia ajudarme? mismo con su comentario yo no consegui!

HugoFortunato avatar Jan 11 '22 15:01 HugoFortunato

@HugoFortunato

Hi bro. With the following block of code on the plugins of gatsby-config.js the problem is partially fixed, in a moment I will explain why.

module.exports = {
  plugins: [
    {
      resolve: `gatsby-source-strapi`,
      options: {
        apiURL: `http://localhost:1337`,
        collectionTypes: [
          {
            name: `categories`,
            endpoint: "api/categories",
          }, //Repeat for each of your collection types
        ],
      },
    },
  ],
}

With this configuration, you can query some things, but certain things don't work. This is not a problem of our code, it's a problem of the gatsby-source-strapi plugin and as they say in their repository, the gatsby-source-strapi plugin isn't supported for gatsby v4 (they are working on it).

In this url you can find some other solutions for your problem. I hope it helps you.

In my case with this configuration, I can query the things I have in my strapi, except the images, that I can't find them in the graphql.

Jofay-zs avatar Jan 11 '22 17:01 Jofay-zs

@Jofay-zs

Man! You're a special guy! Thank you so much! This solve my problem! Thank!!!!!!

HugoFortunato avatar Jan 11 '22 18:01 HugoFortunato

Take note that this isn't a fully-functioning crutch. While I was exploring this, while yes, adding the api/ in there would work for Strapi Collection Types, for some reason the Single Types need a populate query param for it to be usable to Gatsby i.e. return everything in the query.

By default, according to the docs, Strapi will "not populate any relations, media fields, components, or dynamic zones". Which means, if you're using the Strapi blog starter (that has preloaded SEO and articles and whatnot) like I have, or really, if you've just added a compound data field, Strapi will not return it via api if you didn't append the required query parameter.

Therefore, /api/categories isn't enough. It needs /api/categories?populate=* to return all the fields you need.

I think at this point it's a safe bet to just wait til Strapi gets gatsby-source-strapi working nicely with both Gatsby and Strapi V4.

alecgerona avatar Jan 16 '22 21:01 alecgerona