WebSocketListener: make cookies+session optional
This commit is contained in:
parent
4291f73a55
commit
fe772c4e14
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "wms-core",
|
"name": "wms-core",
|
||||||
"version": "0.17.1",
|
"version": "0.17.2",
|
||||||
"description": "Node web framework",
|
"description": "Node web framework",
|
||||||
"repository": "git@gitlab.com:ArisuOngaku/wms-core.git",
|
"repository": "git@gitlab.com:ArisuOngaku/wms-core.git",
|
||||||
"author": "Alice Gaudon <alice@gaudon.pro>",
|
"author": "Alice Gaudon <alice@gaudon.pro>",
|
||||||
|
@ -15,5 +15,5 @@ export default abstract class WebSocketListener<T extends Application> {
|
|||||||
|
|
||||||
public abstract path(): string;
|
public abstract path(): string;
|
||||||
|
|
||||||
public abstract async handle(socket: WebSocket, request: IncomingMessage, session: Express.SessionData): Promise<void>;
|
public abstract async handle(socket: WebSocket, request: IncomingMessage, session: Express.SessionData | null): Promise<void>;
|
||||||
}
|
}
|
@ -13,7 +13,13 @@ export default class MagicLinkWebSocketListener extends WebSocketListener<any> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async handle(socket: WebSocket, request: IncomingMessage, session: Express.SessionData): Promise<void> {
|
async handle(socket: WebSocket, request: IncomingMessage, session: Express.SessionData | null): Promise<void> {
|
||||||
|
// Drop if requested without session
|
||||||
|
if (!session) {
|
||||||
|
socket.close(1002, 'Session is required for this request.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Refuse any incoming data
|
// Refuse any incoming data
|
||||||
socket.on('message', () => {
|
socket.on('message', () => {
|
||||||
socket.close(1003);
|
socket.close(1003);
|
||||||
|
@ -39,7 +39,9 @@ export default class WebSocketServerComponent extends ApplicationComponent<void>
|
|||||||
socket.close(1002, `Path not found ${request.url}`);
|
socket.close(1002, `Path not found ${request.url}`);
|
||||||
return;
|
return;
|
||||||
} else if (!request.headers.cookie) {
|
} else if (!request.headers.cookie) {
|
||||||
socket.close(1002, `Can't process request without cookies.`);
|
listener.handle(socket, request, null).catch(err => {
|
||||||
|
Logger.error(err, 'Error in websocket listener.');
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user