iq4u8 commited on
Commit Β·
7e1854f
1
Parent(s): ffee1b0
fix: adaptive proxy tries HTTP then HTTPS - works regardless of aaPanel SSL state
Browse files387 unmodified lines388389390391392393394395396397398399400401402403404405406407408409387 unmodified lines// ββ AAPANEL REVERSE PROXY (no prefix β direct path interception) ββconst AAPANEL_PORT = 8888;function proxyToPanel(req, res) {const proxyOpts = {hostname: '127.0.0.1',port: AAPANEL_PORT,path: req.originalUrl || req.url,method: req.method,headers: { ...req.headers, host: `127.0.0.1:${AAPANEL_PORT}` }};const proxyReq = http.request(proxyOpts, (proxyRes) => {res.writeHead(proxyRes.statusCode, proxyRes.headers);proxyRes.pipe(res);});proxyReq.on('error', (e) => {res.status(502).json({ error: 'aaPanel not running. Install via terminal: sudo bt' });});req.pipe(proxyReq);}// Known aaPanel paths β intercept before VPS routesconst btPaths = ['/static', '/login', '/public', '/site', '/config',387 unmodified lines388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423387 unmodified lines// ββ AAPANEL REVERSE PROXY (no prefix β direct path interception) ββconst AAPANEL_PORT = 8888;const https = require('https');function proxyToPanel(req, res) {const reqPath = req.originalUrl || req.url;const baseHeaders = { ...req.headers, host: `127.0.0.1:${AAPANEL_PORT}` };// Try HTTP first, then HTTPS with self-signed certfunction tryProxy(useHttps) {const mod = useHttps ? https : http;const proxyOpts = {hostname: '127.0.0.1',port: AAPANEL_PORT,path: reqPath,method: req.method,headers: baseHeaders,rejectUnauthorized: false // accept self-signed certs};const proxyReq = mod.request(proxyOpts, (proxyRes) => {res.writeHead(proxyRes.statusCode, proxyRes.headers);proxyRes.pipe(res);});proxyReq.on('error', (e) => {if (!useHttps && (e.code === 'ECONNRESET' || e.code === 'ECONNREFUSED' || e.code === 'HPE_INVALID_CONSTANT')) {// HTTP failed, try HTTPStryProxy(true);} else {if (!res.headersSent) res.status(502).json({ error: 'aaPanel not running. Install via terminal: sudo bt' });}});req.pipe(proxyReq);}tryProxy(false);}// Known aaPanel paths β intercept before VPS routesconst btPaths = ['/static', '/login', '/public', '/site', '/config',
server.js+29-15