print request info to console/log when it's an image request
As we take control of the request at this point and don't hand the control back, we never hit the logger line on the next hook.
This commit is contained in:
parent
9acdd8ad13
commit
5e271af9c9
1 changed files with 9 additions and 5 deletions
14
index.ts
14
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<string, Media>();
|
||||
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();
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue