import { Application , Injectable , IPlugin } from '@tiejs/common' ; import { Request , Response , NextFunction } from 'express' ; import { als } from './als' ; @ Injectable ( ) export class AlsPlugin implements IPlugin { async middlewareDidReady ( app ) { app . use ( async ( req , res , next ) => { await als . run ( new Map ( ) , async ( ) => { const store = als . getStore ( ) as any ; store . set ( 'req' , req ) ; store . set ( 'res' , res ) ; try { return next ( ) ; } catch ( error ) { throw new Error ( error as any ) ; } } ) ; } ) ; } }