Jeff Chung
Jeff Chung

Reputation: 186

Nestjs websocket port by configuration and cors

I wonder how to a specific port according to the config service provider https://docs.nestjs.com/websockets/gateways ? For e.g, I want to listen to 8500 in my production environment but 8080 in my staging environment.

And how to allow cors on, because when I connect to the socket-server in the different domain it show has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

Upvotes: 4

Views: 3618

Answers (1)

WTF
WTF

Reputation: 37

const options = {
  cors: {
    origin: ["example1.com", "example2.com"],
    methods: ["GET", "POST"],
    credentials: true
  }
}
@WebSocketGateway(options)

Upvotes: 3

Related Questions