const HTTPServer = require("./_http"); const { fetchProxy } = HTTPServer; function logger (...p) { //return; console.log("[DEBUG.http.reverse]:", ...p); } module.exports = class HTTPReverse extends HTTPServer { static type () { return "proxy"; } constructor (adr, syntaxTree) { super(adr, syntaxTree); } run () { this.preinit(); const reverseTo = this.syntax.target ?? "https://example.org"; this.app.use("*", async (req, res) => { logger("REQ HEADERS:>", req.headers); logger("originalUrl:>", req.originalUrl); const currentDomain = req.hostname; logger("hostname:", currentDomain); const isNotDomained = !this.syntax.domains[currentDomain]; if (!isNotDomained) { return this .callDomain(currentDomain, this.syntax.domains[currentDomain]) .argv(this.syntax.domains[currentDomain].Type.type(), req, res); } return fetchProxy(req, res, reverseTo); }); this.postinit((err) => { if (err) { throw err; } console.log(`HTTP reverse proxy server listened at ${ this.adr.address }:${this.adr.port}`); }); } };