oportunidades 8
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-10-14 08:25:30 +02:00
parent 287e991486
commit ba1c0340ea
9112 changed files with 2199795 additions and 856 deletions
@@ -0,0 +1,55 @@
"use strict";
// Proxy module.
const httpProxy = require('http-proxy');
// Base module.
const Base = require('../auth/base');
// Backup old server creation.
const oldCreateServer = httpProxy.createServer;
// New create server.
const newCreateServer = function(auth, options) {
// Mutated mode.
if (auth instanceof Base) {
// Set proxy flag.
auth.proxy = true;
} else {
// Set correct options.
options = auth;
// Clear authentication value.
auth = null;
}
// Default listener plus authentication check.
let server = oldCreateServer.apply(httpProxy, [options]);
// Authentication provided.
if (auth) {
// Override proxyRequest.
let oldProxyRequest = server.web;
server.web = function (req, res) {
// Fetch external arguments.
let externalArguments = arguments;
// Check for authentication.
auth.check(req, res, (req, res, err) => {
if (err) {
console.error(err);
res.statusCode = 400;
res.end (err.message);
} else {
oldProxyRequest.apply(server, externalArguments)
}
});
};
}
// Return server.
return server;
};
// Add authentication method.
httpProxy.createServer = httpProxy.createProxyServer = httpProxy.createProxy = newCreateServer;