Nestjs websocket port by configuration and cors

I wonder how to a specific port according to the config service provider ? 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.