Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
[proxy]优化JavascriptAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
iwind committed Nov 13, 2019
1 parent 61e6390 commit c75ecc6
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/main/web/libs/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ http.Server = function (options) {
}
}
}

this.findBackend = function (backendId) {
for (var i = 0; i < this.backends.length; i++) {
if (this.backends[i].id == backendId) {
return this.backends[i];
}
}

// location
for (var i = 0; i < this.locations.length; i++) {
var backend = this.locations[i].findBackend(backendId);
if (backend != null) {
return backend;
}
}

return null;
};
};

http.Backend = function (options) {
Expand All @@ -46,6 +64,7 @@ http.Backend = function (options) {
this.isDown = false;
this.isBackup = false;
this.name = [];
this.code = "";

if (options != null && typeof (options) == "object") {
for (var key in options) {
Expand All @@ -67,6 +86,7 @@ http.Location = function (options) {
this.root = "";
this.rewrite = [];
this.websocket = {};
this.backends = [];

if (options != null && typeof (options) == "object") {
for (var key in options) {
Expand All @@ -84,11 +104,30 @@ http.Location = function (options) {
var rewrite = new http.Rewrite(value[i]);
this.rewrite.push(rewrite);
}
} else if (typeof (key) == "string" && typeof (this[key]) == typeof (value)) {
}
// backends
else if (key == "backends") {
for (var i = 0; i < value.length; i++) {
var backend = new http.Backend(value[i]);
this.backends.push(backend);
}
}
// others
else if (typeof (key) == "string" && typeof (this[key]) == typeof (value)) {
this[key] = value;
}
}
}

this.findBackend = function (backendId) {
for (var i = 0; i < this.backends.length; i++) {
if (this.backends[i].id == backendId) {
return this.backends[i];
}
}

return null;
};
};

http.Fastcgi = function (options) {
Expand Down

0 comments on commit c75ecc6

Please sign in to comment.