快速问题:我为Strapi CMS创建了一个API获取函数,但似乎无法得到正确的JSON。这导致我的API调用在Strapi (200 OK HTTP)中添加了一个新项。但没有提供的数据。我猜JSON格式错误,数据丢失。
什么工作:
Authorization API request works (200)在Strapi CMS中有一篇空文章
不起作用的:
数据不会在CMS中设置。代码:
// POST request using fetch with error handling
function setArticle() {
const requestOptions =
在strapi v3中,您可以通过以下方式进行原始sql查询:
const data = await strapi.db.connection.raw(`SELECT * from table`);
但是,在启用类型记录的strapi v4中,同一行会出现以下错误:
Property 'connection' does not exist on type 'Database'.
我已经搜索了文档,但找不到如何在启用类型记录的情况下在strapi 4中创建自定义sql查询。
我得到了下面的错误,我不知道是怎么回事:
我仔细阅读了文档,并根据在找到的一个示例制作了一个docker-compose.yml
api_1 | Using strapi 3.0.0-beta.19.3
api_1 | No project found at /srv/app. Creating a new strapi project
api_1 | Creating a new Strapi application at /srv/app.
api_1 |
api_1 | ⛔️ You can only create a Stra
我正在尝试从docker容器访问运行在主机上的mysql。
在我的服务器上,我运行的是mysql版本的5.7.39。我访问了新的mysql数据库和用户,并授予了所有特权:
CREATE DATABASE strapi CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'strapi'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON strapi.* TO 'strapi'@
我尝试从其中使用PostgreSQL安装strapi,我在YAML文件中更改了已挂载卷的名称,并保持所有其余内容与文档中给定的相同。
基于strapi docker-compose.yaml文件
version: '3'
services:
strapi:
image: strapi/strapi
# totally the same as doc
volumes:
- ./backend:/srv/app
# totally the same as doc
postgres:
image: postgres
我使用strapi作为我所有数据流的后端,我创建了单类型的内容,这个类型有不同的组件。在配置了所有的单类型之后,我尝试通过rest获取数据,但没有将json数据作为响应。
This is my json response
This is my single-type structure
请如何解决这个问题:
[2021-11-12T10:48:02.075Z] debug ⛔️ Server wasn't able to start properly.
[2021-11-12T10:48:02.076Z] error TypeError: Cannot convert undefined or null to object
at Function.values (<anonymous>)
at Object.load (/home/mondher/plateforme/node_modules/strapi-database/lib/con
我正在对Strapi进行实验,并希望创建一个由单元测试验证的控制器。
如何在Strapi中设置单元测试?
我写了下面的测试
test('checks entity inside boundary',async ()=> {
ctx={};
var result = await controller.findnearby(ctx);
result = {};
expect(result).anyting();
});
但是,在我的控制器中,我有访问全局strapi对象的代码,这会导致错误ReferenceError: strapi is no