Strapi路线返回404 Not found

时间:2018-04-26 12:03:30

标签: docker strapi

我遇到问题,我的API中的所有路由都返回404 Not found。我在strapi/strapi-docker跟踪了从Docker Hub拉部分。

除了运行图像之外,我所做的是创建一个名为post的新内容类型,其中包含三个字段。如果我尝试GET /post(添加所有帖子),我会收到未经授权的响应错误。预计在此阶段。在我检查角色&允许Public角色使用find和findOne路由的权限我改为获得404 Not found响应错误,即使已添加数据。

开发服务器不使用任何前缀。

find和findOne的

post路由如下所示:

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

strapi界面中没有很多选项可供选择,所以我不知道还有什么可以尝试。我尝试了几种其他的strapi安装。不确定是否可能搞砸了但是我依旧记得在尝试使用strapi / strapi-docker并让它开始工作之前。

1 个答案:

答案 0 :(得分:0)

我多次偶然发现这个问题,最简单的答案通常是:

你发布过任何帖子吗?

Strapi 有一个发布子系统,它通常在创建任何集合、单一类型或组件时打开。 enter image description here

因此,当您创建任何已创建类型的任何内容时,数据将保存为草稿且不公开。

这是我的链接集合类型。已保存,但未发布。

enter image description here

因此,如果您尝试测试端点,但您只有一个数据条目并且设置为草稿,则不会显示任何数据。

enter image description here

没有数据!

enter image description here

单一类型未发布的情况

enter image description here

这将返回 404!

enter image description here

发布,瞧...

enter image description here

这可能是 Strapi 向您发送 404 或仅发送空数组的原因之一!

相关问题