add server settings store

This commit is contained in:
Nystik
2026-06-06 01:16:01 +02:00
parent 3129ed377c
commit 938a698795
4 changed files with 104 additions and 17 deletions

View File

@@ -2,6 +2,11 @@ const { WebSocketServer } = require("ws");
const url = require("url");
const watcher = require("./watcher");
// Null / undefined / empty array means no Origin check.
function toOriginSet(list) {
return Array.isArray(list) && list.length > 0 ? new Set(list) : null;
}
function setupWebSocket(server, opts = {}) {
const { getVaultPath, originAllowlist } = opts;
@@ -9,14 +14,14 @@ function setupWebSocket(server, opts = {}) {
throw new Error("setupWebSocket: opts.getVaultPath is required");
}
// Null / undefined / empty array = no Origin check.
const originSet =
Array.isArray(originAllowlist) && originAllowlist.length > 0
? new Set(originAllowlist)
: null;
let originSet = toOriginSet(originAllowlist);
const wss = new WebSocketServer({ server, path: "/ws" });
wss.setOriginAllowlist = function (list) {
originSet = toOriginSet(list);
};
// Global message handlers: type -> handler(msg, ws).
wss.messageHandlers = new Map();