Route GitLab stats and health checks through a configurable proxy

This commit is contained in:
2026-09-07 09:51:47 +02:00
parent dfe246b7ca
commit e41e2f928f
5 changed files with 176 additions and 39 deletions
+24 -8
View File
@@ -13,6 +13,7 @@ const https = require("https");
const fs = require("fs");
const path = require("path");
const { URL } = require("url");
const { proxyFor, connectThroughProxy, proxiedRequestOptions } = require("./proxy");
const OUT_FILE = process.env.OUT_FILE || "/usr/share/nginx/html/data.json";
const TZ = process.env.TZ || "UTC";
@@ -41,18 +42,33 @@ const GITLAB_TOKEN = process.env.GITLAB_TOKEN || "";
const OPENWEBUI_URL = process.env.OPENWEBUI_URL || "http://100.103.83.12:3000";
const OPENWEBUI_TOKEN = process.env.OPENWEBUI_TOKEN || "";
function request(url, options = {}) {
// Central outbound request helper: honors the outbound proxy (GITLAB_PROXY)
// for the configured host — see api/proxy.js.
async function request(url, options = {}) {
const u = new URL(url);
const client = u.protocol === "https:" ? https : http;
const requestOptions = {
method: options.method || "GET",
headers: options.headers || {},
timeout: options.timeout || 15000,
};
const proxy = proxyFor(url);
if (proxy) {
// https is tunneled through the proxy via CONNECT; plain http uses an
// absolute-form request URI addressed to the proxy.
let socket = null;
if (u.protocol === "https:") {
socket = await connectThroughProxy(proxy, url, requestOptions.timeout);
}
Object.assign(requestOptions, proxiedRequestOptions(proxy, url, socket));
}
return new Promise((resolve, reject) => {
const start = Date.now();
const u = new URL(url);
const client = u.protocol === "https:" ? https : http;
const req = client.request(
u,
{
method: options.method || "GET",
headers: options.headers || {},
timeout: options.timeout || 15000,
},
requestOptions,
(res) => {
let body = "";
res.setEncoding("utf8");