Still working to update finding reverse proxies
This commit is contained in:
parent
19e106fb58
commit
46ce2f55d1
|
|
@ -70,7 +70,7 @@ import ButtonTest from '../views/ButtonTest.vue';
|
|||
//console.log(routes);
|
||||
//console.log("Filtering Caddy Config");
|
||||
//findRps(routes);
|
||||
let rp_dict = findRPRecursively(routes);
|
||||
let rp_dict = searchBaseRoutes(routes);
|
||||
console.log(rp_dict);
|
||||
}
|
||||
|
||||
|
|
@ -80,97 +80,8 @@ import ButtonTest from '../views/ButtonTest.vue';
|
|||
}
|
||||
}
|
||||
|
||||
function findRps(routes) {
|
||||
console.log ("Searching for reverse_proxy");
|
||||
// We're interested in routes and handlers. We specifically want subroutes and reverse_proxy handler
|
||||
|
||||
// routes are lists of handles
|
||||
// handles are lists of routes
|
||||
// subroute handler will have a routes list of more handles
|
||||
|
||||
let rpDictionary = {};
|
||||
|
||||
for(let r_key in routes) {
|
||||
// In each route, we'll look at the first layer of handles
|
||||
// Actually, we need to find subroute, since subroute is what holds the reverse_proxy!
|
||||
|
||||
// Then in each route, search for the match list to get the hosts (only if first layer reverse_proxy is found)
|
||||
//let rp_found = false;
|
||||
// Loop over handle list
|
||||
var caddy_rp = null;
|
||||
var caddy_hn = null;
|
||||
|
||||
for(let h_key in routes[r_key].handle){
|
||||
// Check if the route.handle.handler == "subroute"
|
||||
let rp_found = false;
|
||||
if( routes[r_key].handle[h_key].handler === "subroute" ) {
|
||||
console.log(routes[r_key].handle[h_key]);
|
||||
for(let r2_key in routes[r_key].handle[h_key].routes) {
|
||||
for(let h2_key in routes[r_key].handle[h_key].routes[r_key].handler){
|
||||
if ( routes[r_key].handle[h_key].routes[r_key].handle[h2_key].handler === "reverse_proxy") {
|
||||
//let x = routes[r_key].handle[h_key].routes[r2_key].handle[h2_key].upstreams[0].dial;
|
||||
caddy_rp = routes[r_key].handle[h_key].routes[r2_key].handle[h2_key].upstreams[0].dial;
|
||||
//console.log("reverse proxy found. Address is: " + x);
|
||||
rp_found = true;
|
||||
}
|
||||
if(rp_found === true){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(rp_found === true){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
caddy_hn = routes[r_key].match[0].host[0];
|
||||
rpDictionary[caddy_hn] = caddy_rp;
|
||||
console.log(`Hostname ${caddy_hn} will be proxied to ${caddy_rp}`);
|
||||
//if(rp_found === true){
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
//console.log("rp hostname is " + routes[r_key].match[0].host[0]);
|
||||
|
||||
//if (rp_found === true) {
|
||||
// break;
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
// We need to find the handle in all of these (most likely the base route at this point in time)
|
||||
|
||||
// Search through the K-V pairs. Look for the 'Handle' key. This is a list
|
||||
// Search this List for handler 'subroute'
|
||||
// If it exists, look at the routes list it contains
|
||||
// Search handle list
|
||||
}
|
||||
|
||||
// Look to expand and use recursion by searching routes and handles. Can have two separate functions
|
||||
|
||||
function findRPRecursively(routes) {
|
||||
console.log("Searching recursively!");
|
||||
console.log(routes);
|
||||
let rpDictionary = {};
|
||||
for (let r_key in routes) {
|
||||
for (let h_key in routes[r_key].handle){
|
||||
|
||||
let handle = routes[r_key].handle[h_key];
|
||||
|
||||
if (handle.handler === "subroute"){
|
||||
console.log("Found subroute!");
|
||||
findRPRecursively(routes[r_key].handle[h_key].routes)
|
||||
}
|
||||
if (handle.handler === 'reverse_proxy'){
|
||||
console.log("Found reverse proxy!");
|
||||
console.log(routes)
|
||||
let host = routes[r_key].match.host;
|
||||
rpDictionary[host] = handle.upstreams[0].dial;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rpDictionary
|
||||
}
|
||||
|
||||
|
||||
|
||||
// So what we should do: break apart the routes into handlers and matches. First search the handlers to see if you find subroute or rp.
|
||||
|
|
@ -204,6 +115,7 @@ import ButtonTest from '../views/ButtonTest.vue';
|
|||
|
||||
}
|
||||
|
||||
return handles;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue