#app.useGlobalPipes & app.enableCors does not work for gateway ?

3 messages · Page 1 of 1 (latest)

wraith tapir
#

Hi,
When I set the useGlobalPipes and the enableCors in the main.ts it does not work in the gateway.
I have to add it directly in the gateway file like that :

@UsePipes(new ValidationPipe({ whitelist: true }))
@WebSocketGateway({
    cors: {
        origin: '*',
        methods: 'GET'
    }
})
export class MessagesGateway {

main.ts :

const app = await NestFactory.create(AppModule);
app.useGlobalPipes(new ValidationPipe({
    whitelist: true,
}));
app.enableCors({ 
    origin: '*',
    methods: 'GET', 
});
await app.listen(80);

Is that normal ?

#

I precise that the ValidationPipe is working for the http request

stiff python
#

Global pipes (and other enhancers) doesn't work for gateways. I think we mention that somewhere in the docs