mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
add server settings store
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user