File tree Expand file tree Collapse file tree 3 files changed +15
-4
lines changed
Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,12 @@ export const corsOptions = {
3131 credentials : true ,
3232} ;
3333
34+ if ( corsOptions . origins . length > 1 && process . env . NODE_ENV === "production" ) {
35+ console . warn (
36+ "WARNING: socket.io only supports one cors origin, therefore only first origin will be registered." ,
37+ ) ;
38+ }
39+
3440app . use ( cors ( corsOptions ) ) ;
3541app . use ( csrf ( corsOptions ) ) ;
3642
Original file line number Diff line number Diff line change 1- type Config = {
1+ export type Config = {
22 origins : string [ ] ; // allowed origins
33 methods ?: string [ ] ; // Access-Control-Allow-Methods
44 credentials ?: boolean ; // Access-Control-Allow-Credentials
@@ -47,4 +47,4 @@ function assertValidConfig(config: Config) {
4747 }
4848}
4949
50- export { validateConfig , type Config } ;
50+ export { validateConfig } ;
Original file line number Diff line number Diff line change @@ -3,12 +3,17 @@ import type { Message, UserID } from "common/types";
33import type { CorsOptions } from "cors" ;
44import { type Socket , Server as SocketIOServer } from "socket.io" ;
55import { getUserIdFromToken } from "../../firebase/auth/db" ;
6+ import type { Config as CorsConfig } from "../cross-origin/share" ;
67
78const users = new Map < UserID , Socket > ( ) ;
89
9- export function initializeSocket ( server : Server , corsOptions : CorsOptions ) {
10+ export function initializeSocket ( server : Server , corsOptions : CorsConfig ) {
11+ const cors : CorsOptions = {
12+ origin : corsOptions . origins [ 0 ] ,
13+ ...corsOptions ,
14+ } ;
1015 const io = new SocketIOServer ( server , {
11- cors : corsOptions ,
16+ cors,
1217 connectionStateRecovery : { } ,
1318 } ) ;
1419
You can’t perform that action at this time.
0 commit comments