You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

19 lines
650 B

import { ExecutionContext } from '@nestjs/common';
/**
* Gives the underlying HTTP request of a request of any kind. A tool of the
* model context protocol is a message handler, hence its execution context is
* not of the kind http and the request has to be taken from the context of the
* message instead.
*/
export function getRequest<T>(context: ExecutionContext): T | undefined {
if (context.getType() === 'http') {
return context.switchToHttp().getRequest<T>();
}
const contextOfMessage = context.switchToRpc().getContext<{
getRawRequest?: <U>() => U | undefined;
}>();
return contextOfMessage?.getRawRequest?.<T>();
}