async function eventsHandler(request, response, next) {
	const authHeader = request.get('Authorization');

	if (!sdkPoolManager.checkValidKey(authHeader)) {
		return response.status(500).send({
			message : 'Invalid authentication key'
		});
	}

	console.log(request.get('Authorization'));
	response.writeHead(200, headers);

	const clientId = Date.now();

	const newClient = new Client({
		id               : clientId,
		response,
		authorizationKey : authHeader
	});

	sdkPoolManager.addClient(newClient);

	request.on('close', () => {
		console.log(`${clientId} Connection closed`);
		sdkPoolManager.removeClient(newClient);
	});

	const init = {
		eventType : 'CREATE_CONNECTION',
		payload   : []
	};
	await jsw.fetchRecentData();

	// initial payload is empty
	console.log('SDK client connected');
	newClient.write(`data: ${JSON.stringify(init)}\n\n`);
}
/*
Note that this route should not be available unless someone
requests with a valid key for security reasons.
*/
Note that this route should not be available unless someone
requests with a valid key for security reasons.
Note that this route should not be available unless someone requests with a valid key for security reasons .
async function eventsHandler(request, response, next) {
	const authHeader = request.get('Authorization');
	if (!sdkPoolManager.checkValidKey(authHeader)) {
		return response.status(500).send({
			message : 'Invalid authentication key'
		});
	}
	console.log(request.get('Authorization'));
	response.writeHead(200, headers);
	const clientId = Date.now();
	const newClient = new Client({
		id               : clientId,
		response,
		authorizationKey : authHeader
	});
	sdkPoolManager.addClient(newClient);
	request.on('close', () => {
		console.log(`${clientId} Connection closed`);
		sdkPoolManager.removeClient(newClient);
	});
	const init = {
		eventType : 'CREATE_CONNECTION',
		payload   : []
	};
	await jsw.fetchRecentData();
	console.log('SDK client connected');
	newClient.write(`data: ${JSON.stringify(init)}\n\n`);
}
async function eventsHandler ( request , response , next ) { const authHeader = request . get ( 'Authorization' ) ; if ( ! sdkPoolManager . checkValidKey ( authHeader ) ) { return response . status ( 500 ) . send ( { message : 'Invalid authentication key' } ) ; } console . log ( request . get ( 'Authorization' ) ) ; response . writeHead ( 200 , headers ) ; const clientId = Date . now ( ) ; const newClient = new Client ( { id : clientId , response , authorizationKey : authHeader } ) ; sdkPoolManager . addClient ( newClient ) ; request . on ( 'close' , ( ) => { console . log ( ` ${ clientId } ` ) ; sdkPoolManager . removeClient ( newClient ) ; } ) ; const init = { eventType : 'CREATE_CONNECTION' , payload : [ ] } ; await jsw . fetchRecentData ( ) ; console . log ( 'SDK client connected' ) ; newClient . write ( ` ${ JSON . stringify ( init ) } \n \n ` ) ; }
Note that this route should not be available unless someone
requests with a valid key for security reasons.
Note that this route should not be available unless someone requests with a valid key for security reasons .
// initial payload is empty