strapi - 有没有办法将我在 UI 中看到的strapi 错误消息重定向到标准输出?
问题描述
我正在使用Strapi v3.0.0-beta.18.7 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"
]
}
}
推荐阅读
- c# - 使用 SQLite Xamarin 表单替换或更新表中的特定值
- javascript - 删除实时数据库上的数据 - Firebase
- php - Laravel Force HTTPS 重定向你太多次
- python - 自然对熊猫中的数据框列进行排序
- database - 在不同的节点上部署微服务及其数据库
- ruby-on-rails - Rails 5.0.1 升级后 RSpec 测试套件未运行
- html - 关于导航栏的疑惑
- ios - 创建自定义 UITabBar 控制器并使用分隔符突出显示选定的选项卡
- css - 使用负边距时内容隐藏
- python - 如何在 Python 中访问 i 之前的索引?