Initial commit — status checker service
All checks were successful
Docker / build-and-push (push) Successful in 35s
All checks were successful
Docker / build-and-push (push) Successful in 35s
Polls Nginx Proxy Manager API for proxy hosts matching configurable domain patterns (NPM_INCLUDE_PATTERNS), HTTP-checks each every 60s, serves results as JSON (/api/status) and a terminal-aesthetic HTML page (/). Port 3035. NPM connection and domain filter patterns are fully configurable via environment variables — see README and .env.example. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
42
src/npm.ts
Normal file
42
src/npm.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
export interface ProxyHost {
|
||||
domain_names: string[];
|
||||
forward_host: string;
|
||||
forward_port: number;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
const NPM_BASE = process.env.NPM_BASE_URL ?? 'http://localhost:81';
|
||||
const NPM_EMAIL = process.env.NPM_EMAIL ?? '';
|
||||
const NPM_SECRET = process.env.NPM_SECRET ?? '';
|
||||
|
||||
const rawPatterns = (process.env.NPM_INCLUDE_PATTERNS ?? '\\.goonk\\.se$,\\.dev\\.xplwd\\.com$')
|
||||
.split(',').map(p => new RegExp(p.trim()));
|
||||
const INCLUDE_PATTERNS = rawPatterns;
|
||||
|
||||
let token: string | null = null;
|
||||
let tokenExpiry = 0;
|
||||
|
||||
async function getToken(): Promise<string> {
|
||||
if (token && Date.now() < tokenExpiry) return token;
|
||||
const res = await fetch(`${NPM_BASE}/api/tokens`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ identity: NPM_EMAIL, secret: NPM_SECRET }),
|
||||
});
|
||||
const data = await res.json() as { token: string; expires: string };
|
||||
token = data.token;
|
||||
tokenExpiry = new Date(data.expires).getTime() - 60_000;
|
||||
return token;
|
||||
}
|
||||
|
||||
export async function fetchProxyHosts(): Promise<ProxyHost[]> {
|
||||
const tok = await getToken();
|
||||
const res = await fetch(`${NPM_BASE}/api/nginx/proxy-hosts`, {
|
||||
headers: { Authorization: `Bearer ${tok}` },
|
||||
});
|
||||
const all = await res.json() as ProxyHost[];
|
||||
return all.filter(h =>
|
||||
h.enabled &&
|
||||
h.domain_names.some(d => INCLUDE_PATTERNS.some(p => p.test(d)))
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user