mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
add server settings UI and enforcement
This commit is contained in:
@@ -100,16 +100,20 @@ router.post("/", async (req, res) => {
|
||||
return res.status(400).json({ error: "Missing url" });
|
||||
}
|
||||
|
||||
const proxyMode = settings.get("proxyMode");
|
||||
|
||||
if (proxyMode === "disabled") {
|
||||
return res.status(403).json({ error: "Proxy is disabled" });
|
||||
}
|
||||
|
||||
try {
|
||||
await assertPublicUrl(url);
|
||||
} catch (e) {
|
||||
return res.status(e.statusCode || 400).json({ error: e.message });
|
||||
}
|
||||
|
||||
// When a host allowlist is defined , the proxy only reaches those hosts.
|
||||
const allowlist = settings.get("proxyAllowlist");
|
||||
|
||||
if (allowlist.length > 0) {
|
||||
if (proxyMode === "allowlist") {
|
||||
const allowlist = settings.get("proxyAllowlist");
|
||||
const host = new URL(url).hostname;
|
||||
|
||||
if (!allowlist.includes(host)) {
|
||||
|
||||
@@ -12,11 +12,21 @@ const NUMBER_KEYS = [
|
||||
"writeCoalesceMs",
|
||||
"maxBodyBytes",
|
||||
];
|
||||
const LIST_KEYS = ["proxyAllowlist", "wsOrigins"];
|
||||
const LIST_KEYS = ["proxyAllowlist"];
|
||||
|
||||
function validate(body) {
|
||||
const clean = {};
|
||||
|
||||
if (body.proxyMode !== undefined) {
|
||||
if (!settings.PROXY_MODES.includes(body.proxyMode)) {
|
||||
throw new Error(
|
||||
`proxyMode must be one of: ${settings.PROXY_MODES.join(", ")}`,
|
||||
);
|
||||
}
|
||||
|
||||
clean.proxyMode = body.proxyMode;
|
||||
}
|
||||
|
||||
for (const key of NUMBER_KEYS) {
|
||||
if (body[key] === undefined) {
|
||||
continue;
|
||||
@@ -57,14 +67,8 @@ function validate(body) {
|
||||
return clean;
|
||||
}
|
||||
|
||||
function applySettings(effective, req) {
|
||||
function applySettings(effective) {
|
||||
writeCoalescer.configure({ writeCoalesceMs: effective.writeCoalesceMs });
|
||||
|
||||
const wss = req.app.get("wss");
|
||||
|
||||
if (wss && typeof wss.setOriginAllowlist === "function") {
|
||||
wss.setOriginAllowlist(effective.wsOrigins);
|
||||
}
|
||||
}
|
||||
|
||||
router.get("/", (req, res) => {
|
||||
@@ -81,7 +85,7 @@ router.post("/", (req, res) => {
|
||||
}
|
||||
|
||||
const effective = settings.update(clean);
|
||||
applySettings(effective, req);
|
||||
applySettings(effective);
|
||||
|
||||
// Cache sizes ride in the bootstrap response; clear it so the next page load picks up new values.
|
||||
bootstrapRoutes.invalidateAll();
|
||||
|
||||
Reference in New Issue
Block a user