1 Star 1 Fork 0

masx200 / deno-dns-over-https-server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
logger.tsx 1.61 KB
一键复制 编辑 原始数据 按行查看 历史
import {
Context,
getOriginalOptions,
NextFunction,
RetHandler,
} from "https://cdn.jsdelivr.net/gh/masx200/deno-http-middleware@3.3.0/mod.ts";
import { ConnInfo } from "https://deno.land/std@0.182.0/http/server.ts"; // 导入ConnInfo类型
import { JSONSTRINGIFYNULL4 } from "./JSONSTRINGIFYNULL4.ts";
/**
* 日志记录中间件
*
* @param context 请求上下文
* @param next 下一个中间件函数
* @returns 返回一个Promise,最终处理结果
*/
export async function logger(
context: Context,
next: NextFunction,
): Promise<RetHandler> {
// console.log(context);
const { request } = context;
const { url, method, headers } = request;
const connInfo: ConnInfo = getOriginalOptions(context);
console.log(
JSONSTRINGIFYNULL4(
{
connInfo,
request: {
url,
method,
headers: Object.fromEntries(headers),
},
},
null,
4,
),
);
await next();
const { response } = context;
console.log(
JSONSTRINGIFYNULL4(
{
response: {
// url: request.url,
status: response.status,
// method,
headers: Object.fromEntries(response.headers),
},
connInfo,
request: {
url,
method,
headers: Object.fromEntries(headers),
},
},
null,
4,
),
);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/masx200/deno-dns-over-https-server.git
git@gitee.com:masx200/deno-dns-over-https-server.git
masx200
deno-dns-over-https-server
deno-dns-over-https-server
main

搜索帮助

344bd9b3 5694891 D2dac590 5694891