const HTTPServer = require("./_http"); const mime = require("mime"); const { simpleHTTP } = HTTPServer; function logger (...p) { return; console.log("[DEBUG.http.simple]:", ...p); } module.exports = class HTTPRedirector extends HTTPServer { constructor (adr, syntaxTree) { super(adr, syntaxTree); } run () { this.preinit(); const redirectTo = this.syntax.target ?? "https://example.org"; this.app.use("*", async (req, res) => { 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("shttp", req, res); } return simpleHTTP(redirectTo, req, res, !!this.syntax.showDir); }); this.postinit((err) => { if (err) { throw err; } console.log(`Simple HTTP server listened at ${ this.adr.address }:${this.adr.port}`); }); } };