diff --git a/index.ts b/index.ts index 9b078aa..1dad053 100644 --- a/index.ts +++ b/index.ts @@ -1,4 +1,4 @@ -import Fastify from "fastify"; +import Fastify, { type FastifyReply, type FastifyRequest } from "fastify"; import FastifyFormBody from "@fastify/formbody"; import FastifyMultipart from "@fastify/multipart"; import FastifyCookie from "@fastify/cookie"; @@ -57,6 +57,11 @@ fastify.register(FastifyStatic, { redirect: false }); +function printReqInfo(req: FastifyRequest, res: FastifyReply) { + // @ts-ignore + Console.printInfo(`[ ${req.logType} ] [ ${req.method.toUpperCase()} ] [ ${ConsoleUtility.StatusColor(res.statusCode)} ] [ ${blue(`${Date.now() - req.startTime}ms`)} ] > ${req.url}`); +} + const hashLookupCache = new FunkyArray(); fastify.addHook("preHandler", (req, res, done) => { (async () => { @@ -90,6 +95,8 @@ fastify.addHook("preHandler", (req, res, done) => { "content-length": media.FileSize, })); readStream.pipe(res.raw); + + printReqInfo(req, res); return; } } else { @@ -105,10 +112,7 @@ fastify.addHook("preHandler", (req, res, done) => { }); fastify.addHook("onSend", (req, res, _payload, done) => { - // @ts-ignore - Console.printInfo(`[ ${req.logType} ] [ ${req.method.toUpperCase()} ] [ ${ConsoleUtility.StatusColor(res.statusCode)} ] [ ${blue(`${Date.now() - req.startTime}ms`)} ] > ${req.url}`); - - //console.log(res.getHeaders()); + printReqInfo(req, res); done(); });