feat: Implement background BGP update proxy endpoint and update documentation; refactor frontend components to utilize new API endpoint
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 19m20s

This commit is contained in:
2025-08-13 00:41:32 +07:00
parent 5b80e5faa4
commit 358bfb04b6
5 changed files with 82 additions and 5 deletions
+55
View File
@@ -13,6 +13,9 @@ const rateLimit = require('express-rate-limit');
const pino = require('pino');
const pinoHttp = require('pino-http');
const promClient = require('prom-client');
const http = require('http');
const https = require('https');
const { URL } = require('url');
const app = express();
const port = Number(process.env.PORT) || 3001;
@@ -1835,6 +1838,58 @@ app.post('/api/auto-urls/process', async (req, res) => {
}
});
// --- Proxy: Background BGP Update (avoids CORS from browser) ---
app.post('/api/update-bgp/background', async (req, res) => {
try {
const targetUrl = process.env.BGP_BACKGROUND_URL;
if (!targetUrl) {
return sendError(res, 500, 'BGP_BACKGROUND_URL is not configured', 'E_CONFIG');
}
const u = new URL(targetUrl);
const client = u.protocol === 'https:' ? https : http;
const options = {
method: 'POST',
hostname: u.hostname,
port: u.port || (u.protocol === 'https:' ? 443 : 80),
path: `${u.pathname}${u.search || ''}`,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
timeout: 15000,
};
const body = req.body && Object.keys(req.body).length ? JSON.stringify(req.body) : '';
const upstream = client.request(options, (r) => {
let data = '';
r.setEncoding('utf8');
r.on('data', (chunk) => { data += chunk; });
r.on('end', () => {
const status = r.statusCode || 502;
// Try to parse JSON; fallback to text
try {
const json = data ? JSON.parse(data) : {};
return res.status(status).json(json);
} catch (_) {
return res.status(status).json({ ok: status >= 200 && status < 300, data });
}
});
});
upstream.on('timeout', () => {
try { upstream.destroy(); } catch {}
return sendError(res, 504, 'Upstream timeout', 'E_UPSTREAM_TIMEOUT');
});
upstream.on('error', (e) => {
return sendError(res, 502, 'Upstream error', 'E_UPSTREAM', { error: String(e?.message || e) });
});
if (body) upstream.write(body);
upstream.end();
} catch (e) {
return sendError(res, 500, 'Proxy error', 'E_PROXY', { error: String(e?.message || e) });
}
});
// The "catchall" handler: for any request that doesn't
// match one above, send back React's index.html file.
app.get('*', (req, res) => {