UNPKG

mm_os

Version:

这是超级美眉服务端框架,用于快速构建应用程序。

32 lines 803 B
/** * web日志 * @param {Object} server 服务 * @param {Object} config 配置参数 */ module.exports = function(server, config) { /* 跨域限制(web防火墙) */ server.use(async (ctx, next) => { try { var url = ctx.path + ctx.querystring; var body = ""; if (ctx.request.body) { try { body = JSON.stringify(ctx.request.body); if (body.length > 1024) { body = body.substring(0, 1024) + "..." } } catch (jsonError) { body = "[无法序列化请求体]"; $.log.error('日志中间件JSON序列化错误:', jsonError); } } $.log.http(`${ctx.method}\t${url}\t${body}`); await next(); } catch (error) { $.log.error('log中间件错误:', error); // 确保请求可以继续处理 await next(); } }); return server; };