Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 78a88cf

Browse files
authored
Allow connections without origin. (#34)
Requests initiated from non-web platforms don't have origin.
1 parent 5c2701a commit 78a88cf

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/socketio_server.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,14 @@ exports.create = (config) => {
110110
}
111111

112112
function listen(io, config) {
113-
io.origins(config.allowedOrigins);
113+
io.origins((origin, callback) => {
114+
if (!origin) {
115+
// Requests initiated from non-web platforms don't have origin.
116+
callback(null, true);
117+
} else {
118+
callback(null, config.allowedOrigins.includes(origin));
119+
}
120+
});
114121
io.on('connection', onConnection);
115122
}
116123

@@ -148,4 +155,4 @@ exports.create = (config) => {
148155
secureServer.close();
149156
};
150157
return server;
151-
}
158+
}

0 commit comments

Comments
 (0)