dockerstrapinuxt-strapi

Strapi routes return 404 Not found


I have a problem where all routes in my API return 404 Not found. I followed the Pull from Docker Hub section at strapi/strapi-docker.

What I did, apart from running the images, was creating a new Content type called post containing three fields. If I try GET /post (to get all posts added) I get unauthorized response error. This is expected at this stage. After I check Roles & Permissions to allow the Public role to use the find and findOne routes I instead get a 404 Not found response error even though data has been added.

The dev server does not use any prefix.

post routes for find and findOne looks as the following:

{
  "routes": [
    {
    "method": "GET",
    "path": "/post",
    "handler": "Post.find",
    "config": {
      "policies": []
    }
  },
  {
    "method": "GET",
    "path": "/post/:_id",
    "handler": "Post.findOne",
    "config": {
      "policies": []
    }
  }
}

There are not many options in the strapi interface to fiddle with so I'm not sure what else to try. I have tried a couple of other installations of strapi. Not sure if that could have messed it up but I vaguely remember trying out strapi/strapi-docker before and getting it to work.


Solution

  • I have stumbled upon this issue many times, and the easiest answer usually is:

    Have you published any of your posts?

    Strapi has a publishing subsystem which is usually turned on upon the creation of any collection, single type or component. enter image description here

    So when you create any content of any created type, the data is saved as draft and is not publicly available.

    Here is my link collection type. It is saved, but not published.

    enter image description here

    So if you are trying to test an endpoint, but you only have one single data entry and it is set to draft, no data will show up.

    enter image description here

    No data!

    enter image description here

    In case of a single type that is not published

    enter image description here

    This will return a 404!

    enter image description here

    Publish and, voila ...

    enter image description here

    This could be one reason why strapi is sending you a 404 or only an empty array!