mirror of
https://github.com/tale/headplane.git
synced 2026-08-29 16:37:10 +00:00
feat: switch to a central singleton handler
This also adds support for Headscale TLS installations
This commit is contained in:
+6
-5
@@ -1,8 +1,14 @@
|
||||
import WebSocket, { WebSocketServer } from 'ws';
|
||||
import { hp_setSingleton } from '~server/context/global';
|
||||
import log from '~server/utils/log';
|
||||
import { hp_agentRequest } from './data';
|
||||
|
||||
export function initWebsocket(server: WebSocketServer, authKey: string) {
|
||||
log.info('SRVX', 'Starting a WebSocket server for agent connections');
|
||||
const agents = new Map<string, WebSocket>();
|
||||
hp_setSingleton('ws_agents', agents);
|
||||
hp_setSingleton('ws_fetch_data', hp_agentRequest);
|
||||
|
||||
server.on('connection', (ws, req) => {
|
||||
const tailnetID = req.headers['x-headplane-tailnet-id'];
|
||||
if (!tailnetID || typeof tailnetID !== 'string') {
|
||||
@@ -50,8 +56,3 @@ export function initWebsocket(server: WebSocketServer, authKey: string) {
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
const agents = new Map<string, WebSocket>();
|
||||
export function hp_getAgents() {
|
||||
return agents;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user