mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
feat: add more api logs (#1870)
Adds more detailed API logging using Pino
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { getIpAddress } from './get-ip-address';
|
||||
|
||||
const ZIpSchema = z.string().ip();
|
||||
|
||||
export const ZRequestMetadataSchema = z.object({
|
||||
@ -40,11 +42,13 @@ export type ApiRequestMetadata = {
|
||||
};
|
||||
|
||||
export const extractRequestMetadata = (req: Request): RequestMetadata => {
|
||||
const forwardedFor = req.headers.get('x-forwarded-for');
|
||||
const ip = forwardedFor
|
||||
?.split(',')
|
||||
.map((ip) => ip.trim())
|
||||
.at(0);
|
||||
let ip: string | undefined = undefined;
|
||||
|
||||
try {
|
||||
ip = getIpAddress(req);
|
||||
} catch {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
const parsedIp = ZIpSchema.safeParse(ip);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user