strapi - 如何将所有strapi UI消息错误重定向到控制台?
问题描述
我正在使用Strapi v3.0.0-beta.18.7
Strapi 在 UI 中抛出了很多数据库错误,但是视觉上里面有错误的 UI 块太小了,无法读取错误的全文。
如何 将错误消息重定向到文件/控制台到列表有机会阅读所有错误文本?
解决方案
我建议使用自定义中间件来管理您的需求。
这是创建中间件的文档 - https://strapi.io/documentation/3.0.0-beta.x/concepts/middlewares.html
第一步:创建中间件
路径——middlewares/log/index.js
module.exports = strapi => {
return {
initialize() {
strapi.app.use(async (ctx, next) => {
await next();
const status = ctx.status;
if (status < 200 || status >= 300) {
console.log(ctx.body);
}
});
},
};
};
第 2 步:启用中间件
路径——config/environments/development/middleware.json
{
"log": {
"enabled": true
}
}
第三步:按正确的顺序设置中间件
路径——config/middleware.json
{
"timeout": 100,
"load": {
"before": [
"log",
"responseTime",
"logger",
"cors",
"responses",
"gzip"
],
"order": [
"Define the middlewares' load order by putting their name in this array is the right order"
],
"after": [
"parser",
"router"
]
}
}
推荐阅读
- java - 如何在Java中等待一个进程
- javascript - 过滤数组并形成新数组
- c++ - 使用类、对象和构造函数 / C++
- c++ - campare 一个长变量,INT_MAX + 1
- javascript - 我可以将反应应用添加到 app.html 而不是 index.html
- excel - 嵌套Excel公式修改问题
- javascript - php中提交表单的计数器
- javascript - 将每个单词的第一个和最后一个字母大写的功能不起作用
- sql - 选择“高”列中的前 5 个最大记录,并从同一查询中的“低”列和按股票名称分区的同一个表中选择 5 个最小记录
- vue.js - Apollo 订阅在客户端不起作用