27 lines
984 B
TypeScript
Raw Normal View History

2023-05-23 20:53:26 -04:00
import { NextFunction, Request, Response } from "express";
2023-05-19 15:22:48 -03:00
const unknownEndpointHandler = (request: Request, response: Response) => {
console.error("[ERROR] Unknown Endpoint", request.url);
response.status(404).json({ error: "endpoint was not found" });
2023-05-19 15:22:48 -03:00
};
const requestLogger = (request: Request, _response: Response, next: NextFunction) => {
console.log("Method:", request.method);
console.log("Path: ", request.path);
2023-05-29 07:01:40 +08:00
if (Buffer.isBuffer(request.body)) {
const str = request.body.toString();
const index = str.lastIndexOf("}");
const jsonSubstring = str.substring(0, index + 1);
console.log("Body: ", jsonSubstring);
request.body = jsonSubstring;
if (str.length > jsonSubstring.length) {
const token = str.substring(index + 1, str.length).trim();
console.log("Token: ", token);
}
}
console.log("---");
next();
2023-05-19 15:22:48 -03:00
};
export { unknownEndpointHandler, requestLogger };