mirror of
https://github.com/tale/headplane.git
synced 2026-08-21 18:26:38 +00:00
feat: use a new ws implementation thats encapsulated
This commit is contained in:
+16
-10
@@ -1,9 +1,10 @@
|
||||
// import { initWebsocket } from '~server/ws';
|
||||
import { constants, access } from 'node:fs/promises';
|
||||
import { createServer } from 'node:http';
|
||||
import { hp_getConfig, hp_loadConfig } from '~server/context/loader';
|
||||
import { listener } from '~server/listener';
|
||||
import log from '~server/utils/log';
|
||||
import { hp_loadAgentCache } from '~server/ws/data';
|
||||
import { initWebsocket } from '~server/ws/socket';
|
||||
|
||||
log.info('SRVX', 'Running Node.js %s', process.versions.node);
|
||||
|
||||
@@ -19,16 +20,21 @@ try {
|
||||
await hp_loadConfig();
|
||||
const server = createServer(listener);
|
||||
|
||||
// const ws = initWebsocket();
|
||||
// if (ws) {
|
||||
// server.on('upgrade', (req, socket, head) => {
|
||||
// ws.handleUpgrade(req, socket, head, (ws) => {
|
||||
// ws.emit('connection', ws, req);
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
const context = hp_getConfig();
|
||||
const ws = initWebsocket(context.server.agent.authkey);
|
||||
if (ws) {
|
||||
await hp_loadAgentCache(
|
||||
context.server.agent.ttl,
|
||||
context.server.agent.cache_path,
|
||||
);
|
||||
|
||||
server.on('upgrade', (req, socket, head) => {
|
||||
ws.handleUpgrade(req, socket, head, (ws) => {
|
||||
ws.emit('connection', ws, req);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
server.listen(context.server.port, context.server.host, () => {
|
||||
log.info(
|
||||
'SRVX',
|
||||
|
||||
Reference in New Issue
Block a user