-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket-io.adapter.ts
More file actions
28 lines (26 loc) · 852 Bytes
/
Copy pathsocket-io.adapter.ts
File metadata and controls
28 lines (26 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { INestApplicationContext } from '@nestjs/common';
import { IoAdapter } from '@nestjs/platform-socket.io';
import { Server, ServerOptions } from 'socket.io';
import { AppConfigService } from '../config/app-config.service';
/**
* Socket.IO adapter that sources its CORS policy from configuration, so the
* WebSocket layer honours the same `CORS_ORIGIN` allow-list as the HTTP layer
* instead of a hardcoded `origin: true`.
*/
export class ConfiguredIoAdapter extends IoAdapter {
constructor(
app: INestApplicationContext,
private readonly config: AppConfigService,
) {
super(app);
}
createIOServer(port: number, options?: ServerOptions): Server {
return super.createIOServer(port, {
...options,
cors: {
origin: this.config.corsOrigins,
credentials: true,
},
}) as Server;
}
}