我有一个问题,我的 API 中的所有路由都返回404 Not found. 我遵循了Strapi/strapi-docker 上的Pull from Docker Hub部分。
除了运行图像之外,我所做的是创建一个名为post包含三个字段的新内容类型。如果我尝试GET /post(添加所有帖子),我会收到未经授权的响应错误。这是现阶段的预期。在检查角色和权限以允许公共角色使用 find 和 findOne 路由后,即使添加了数据,我也会收到 404 Not found 响应错误。
开发服务器不使用任何前缀。
post find 和 findOne 的路由如下所示:
{
"routes": [
{
"method": "GET",
"path": "/post",
"handler": "Post.find",
"config": {
"policies": []
}
},
{
"method": "GET",
"path": "/post/:_id",
"handler": "Post.findOne",
"config": {
"policies": []
}
}
}
Run Code Online (Sandbox Code Playgroud)
Strapi 界面中没有太多选项可以摆弄,所以我不确定还能尝试什么。我已经尝试了一些其他的 Strapi 安装。不确定这是否会搞砸,但我依稀记得之前尝试过 Strapi/strapi-docker 并让它工作。
tsconfig.json:2:14 - 错误 TS6053:找不到文件“@strapi/typescript-utils/tsconfigs/server”。
2“扩展”:“@strapi/typescript-utils/tsconfigs/server”,~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
发现 1 个错误。
当我尝试使用 npx create-strapi-app@latest my-project 命令安装 Strapi 时,出现以下错误
安装依赖项时出错:继续尝试!哦,看来您在项目中安装依赖项时遇到了错误。不要放弃,您的项目已正确创建。修复安装错误中提到的问题并尝试运行以下命令
但是没有错误日志,当我尝试使用纱线安装&&纱线开发时,出现打字稿错误。我系统中的node版本是v18.4
我之前已经安装了 Strapi 版本 4,并且成功,但目前在尝试使用相同命令进行安装时出现此错误。
在我的应用程序初始加载时,我在index.vue. 模板在这里:
<template>
<div v-for="(season, index) in seasons" :key="index">
{{ season.attributes.year }}
</div>
</template>
<script setup>
const { find } = useStrapi()
const { data: seasons } = await find('seasons')
</script>
Run Code Online (Sandbox Code Playgroud)
第一次加载和刷新时的错误是:
Unhandled error during execution of setup function at
<Index onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< undefined > >
Run Code Online (Sandbox Code Playgroud)
GET http://localhost:3000/ 500 (Internal Server Error)
Run Code Online (Sandbox Code Playgroud)
服务器在 localhost 上响应 500。
在我消除错误并从错误状态重新路由到“/”后,我看到了数据,这是刷新和首次加载问题。
我的猜测是该useStrapi函数必须在 onMounted 或类似的东西上被触发?(但如果可能的话,我希望它由服务器端处理)
这可能也会有帮助。我的nuxt.config.ts
export default defineNuxtConfig({
modules: [
'@nuxtjs/strapi'
],
strapi: {
url: process.env.STRAPI_URL || 'http://localhost:1337',
prefix: …Run Code Online (Sandbox Code Playgroud) 我正在使用Strapi和graphQL,
通过这个查询我可以获得帖子
query {
posts{
id,
title
}
}
Run Code Online (Sandbox Code Playgroud)
我想将帖子和总计数放在 一起,理想的结果是这样的
{
"data": {
"totalCount" : "3",
"posts": [
{
"id": "1",
"title": "first post "
},
{
"id": "4",
"title": "post two"
},
{
"id": "5",
"title": "post 3"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我已阅读文档,我可以查询以获得总数,但这对我来说还不够!那么,我怎样才能将帖子和总计数放在一起呢?