mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 08:34:07 -08:00
Add some debug messages
This commit is contained in:
parent
afe0d16a9a
commit
a03d5c6e14
|
@ -23,6 +23,7 @@ export class Push {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.channel.on('disconnect', (channel: string, res: express.Response) => {
|
this.channel.on('disconnect', (channel: string, res: express.Response) => {
|
||||||
|
console.log('>> Push.disconnect');
|
||||||
if (res.req !== undefined) {
|
if (res.req !== undefined) {
|
||||||
delete this.connections[res.req.query.sessionId as string];
|
delete this.connections[res.req.query.sessionId as string];
|
||||||
}
|
}
|
||||||
|
@ -39,13 +40,17 @@ export class Push {
|
||||||
* @memberof Push
|
* @memberof Push
|
||||||
*/
|
*/
|
||||||
add(sessionId: string, req: express.Request, res: express.Response) {
|
add(sessionId: string, req: express.Request, res: express.Response) {
|
||||||
|
console.log('>> Push.add 1');
|
||||||
|
|
||||||
if (this.connections[sessionId] !== undefined) {
|
if (this.connections[sessionId] !== undefined) {
|
||||||
|
console.log('>> Push.add 2');
|
||||||
// Make sure to remove existing connection with the same session
|
// Make sure to remove existing connection with the same session
|
||||||
// id if one exists already
|
// id if one exists already
|
||||||
this.connections[sessionId].end();
|
this.connections[sessionId].end();
|
||||||
this.channel.removeClient(this.connections[sessionId]);
|
this.channel.removeClient(this.connections[sessionId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('>> Push.add 3');
|
||||||
this.connections[sessionId] = res;
|
this.connections[sessionId] = res;
|
||||||
this.channel.addClient(req, res);
|
this.channel.addClient(req, res);
|
||||||
}
|
}
|
||||||
|
@ -63,6 +68,7 @@ export class Push {
|
||||||
|
|
||||||
|
|
||||||
send(type: IPushDataType, data: any, sessionId?: string) { // tslint:disable-line:no-any
|
send(type: IPushDataType, data: any, sessionId?: string) { // tslint:disable-line:no-any
|
||||||
|
console.log('>> Push.send 1');
|
||||||
if (sessionId !== undefined && this.connections[sessionId] === undefined) {
|
if (sessionId !== undefined && this.connections[sessionId] === undefined) {
|
||||||
// TODO: Log that properly!
|
// TODO: Log that properly!
|
||||||
console.error(`The session "${sessionId}" is not registred.`);
|
console.error(`The session "${sessionId}" is not registred.`);
|
||||||
|
@ -74,10 +80,13 @@ export class Push {
|
||||||
data,
|
data,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log('>> Push.send 2');
|
||||||
if (sessionId === undefined) {
|
if (sessionId === undefined) {
|
||||||
|
console.log('>> Push.send 3');
|
||||||
// Send to all connected clients
|
// Send to all connected clients
|
||||||
this.channel.send(JSON.stringify(sendData));
|
this.channel.send(JSON.stringify(sendData));
|
||||||
} else {
|
} else {
|
||||||
|
console.log('>> Push.send 4');
|
||||||
// Send only to a specific client
|
// Send only to a specific client
|
||||||
this.channel.send(JSON.stringify(sendData), [this.connections[sessionId]]);
|
this.channel.send(JSON.stringify(sendData), [this.connections[sessionId]]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,13 +230,23 @@ class App {
|
||||||
|
|
||||||
// Get push connections
|
// Get push connections
|
||||||
this.app.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
|
this.app.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
|
console.log({
|
||||||
|
headers: req.headers,
|
||||||
|
method: req.method,
|
||||||
|
url: req.url,
|
||||||
|
query: req.query,
|
||||||
|
});
|
||||||
|
|
||||||
if (req.url.indexOf('/rest/push') === 0) {
|
if (req.url.indexOf('/rest/push') === 0) {
|
||||||
|
console.log('*** Is Push-Connect-Request');
|
||||||
|
|
||||||
// TODO: Later also has to add some kind of authentication token
|
// TODO: Later also has to add some kind of authentication token
|
||||||
if (req.query.sessionId === undefined) {
|
if (req.query.sessionId === undefined) {
|
||||||
next(new Error('The query parameter "sessionId" is missing!'));
|
next(new Error('The query parameter "sessionId" is missing!'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('*** Push-Connection gets added');
|
||||||
this.push.add(req.query.sessionId as string, req, res);
|
this.push.add(req.query.sessionId as string, req, res);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue