refactor(server): cls (#13814)

This commit is contained in:
Jason Rasmussen 2024-10-29 16:41:47 -04:00 committed by GitHub
parent 2efba6326d
commit 19eb3ed8b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 31 additions and 21 deletions

View file

@ -1,15 +1,12 @@
import { ConfigModuleOptions } from '@nestjs/config';
import { CronExpression } from '@nestjs/schedule';
import { Request, Response } from 'express';
import Joi, { Root } from 'joi';
import { CLS_ID, ClsModuleOptions } from 'nestjs-cls';
import {
AudioCodec,
Colorspace,
CQMode,
ImageFormat,
ImmichEnvironment,
ImmichHeader,
LogLevel,
ToneMapping,
TranscodeHWAccel,
@ -354,17 +351,3 @@ export const immichAppConfig: ConfigModuleOptions = {
),
}),
};
export const clsConfig: ClsModuleOptions = {
middleware: {
mount: true,
generateId: true,
setup: (cls, req: Request, res: Response) => {
const headerValues = req.headers[ImmichHeader.CID];
const headerValue = Array.isArray(headerValues) ? headerValues[0] : headerValues;
const cid = headerValue || cls.get(CLS_ID);
cls.set(CLS_ID, cid);
res.header(ImmichHeader.CID, cid);
},
},
};