mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2026-09-24 13:40:19 +01:00
processItems() passed proxyHostModel and the literal "proxy_host" to configure() for every host type. host_type selects both the template and the output path, and each host type has its own id sequence, so redirection hosts, 404 hosts and streams were rendered through proxy_host.conf and written over /data/nginx/proxy_host/<id>.conf. The proxy host sharing that id lost its config file and had the resulting nginx error recorded in its own meta.
77 lines
2.5 KiB
JavaScript
Executable File
77 lines
2.5 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
import * as process from "node:process"; // Use the node: protocol for built-ins
|
|
import internalNginx from "../internal/nginx.js";
|
|
import { global as logger } from "../logger.js";
|
|
import deadHostModel from "../models/dead_host.js";
|
|
import proxyHostModel from "../models/proxy_host.js";
|
|
import redirectionHostModel from "../models/redirection_host.js";
|
|
import streamModel from "../models/stream.js";
|
|
|
|
const args = process.argv.slice(2);
|
|
const UNATTENDED = args.includes("-y") || args.includes("--yes");
|
|
const DRY_RUN = args.includes("--dry-run");
|
|
|
|
if (args.includes("--help") || args.includes("-h")) {
|
|
console.log("\nThis will iterate over all Hosts and regnerate their Nginx configs.\n")
|
|
console.log("Usage: ./regenerate-config [-h|--help] [-y|--yes] [--dry-run]\n");
|
|
process.exit(0);
|
|
}
|
|
|
|
// ask for the user to confirm the action if not in unattended mode
|
|
if (!UNATTENDED && !DRY_RUN) {
|
|
const readline = await import("node:readline");
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout,
|
|
});
|
|
|
|
const question = (query) =>
|
|
new Promise((resolve) => rl.question(query, resolve));
|
|
|
|
const answer = await question(
|
|
"This will iterate over all Hosts and regnerate their Nginx configs.\n\nAre you sure you want to proceed? (y/N) ",
|
|
);
|
|
rl.close();
|
|
|
|
if (answer.toLowerCase() !== "y") {
|
|
console.log("Aborting.");
|
|
process.exit(0);
|
|
}
|
|
}
|
|
|
|
const logIt = (msg, type = "info") => logger[type](
|
|
`${DRY_RUN ? '[DRY RUN] ' : ''}${msg}`,
|
|
);
|
|
|
|
// Let's do it.
|
|
|
|
const processItems = async (model, type, hostType) => {
|
|
const rows = await model
|
|
.query()
|
|
.where("is_deleted", 0)
|
|
.andWhere("enabled", 1)
|
|
.groupBy("id")
|
|
.allowGraph(model.defaultAllowGraph)
|
|
.withGraphFetched(`[${model.defaultExpand.join(", ")}]`)
|
|
.orderBy(...model.defaultOrder);
|
|
|
|
logIt(`[${type}] Found ${rows.length} rows to process...`);
|
|
for (const row of rows) {
|
|
if (!DRY_RUN) {
|
|
logIt(`[${type}] Regenerating config #${row.id}: ${row.domain_names ? row.domain_names.join(", ") : 'port ' + row.incoming_port}`);
|
|
await internalNginx.configure(model, hostType, row);
|
|
} else {
|
|
logIt(`[${type}] Skipping generation of config #${row.id}: ${row.domain_names ? row.domain_names.join(", ") : 'port ' + row.incoming_port}`);
|
|
}
|
|
}
|
|
};
|
|
|
|
await processItems(proxyHostModel, "Proxy Host", "proxy_host");
|
|
await processItems(redirectionHostModel, "Redirection Host", "redirection_host");
|
|
await processItems(deadHostModel, "404 Host", "dead_host");
|
|
await processItems(streamModel, "Stream", "stream");
|
|
|
|
logIt("Completed", "success");
|
|
process.exit(0);
|