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

Commit c75ecc6

Browse files
committed
[proxy]优化JavascriptAPI
1 parent 61e6390 commit c75ecc6

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

src/main/web/libs/http.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ http.Server = function (options) {
3636
}
3737
}
3838
}
39+
40+
this.findBackend = function (backendId) {
41+
for (var i = 0; i < this.backends.length; i++) {
42+
if (this.backends[i].id == backendId) {
43+
return this.backends[i];
44+
}
45+
}
46+
47+
// location
48+
for (var i = 0; i < this.locations.length; i++) {
49+
var backend = this.locations[i].findBackend(backendId);
50+
if (backend != null) {
51+
return backend;
52+
}
53+
}
54+
55+
return null;
56+
};
3957
};
4058

4159
http.Backend = function (options) {
@@ -46,6 +64,7 @@ http.Backend = function (options) {
4664
this.isDown = false;
4765
this.isBackup = false;
4866
this.name = [];
67+
this.code = "";
4968

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

7191
if (options != null && typeof (options) == "object") {
7292
for (var key in options) {
@@ -84,11 +104,30 @@ http.Location = function (options) {
84104
var rewrite = new http.Rewrite(value[i]);
85105
this.rewrite.push(rewrite);
86106
}
87-
} else if (typeof (key) == "string" && typeof (this[key]) == typeof (value)) {
107+
}
108+
// backends
109+
else if (key == "backends") {
110+
for (var i = 0; i < value.length; i++) {
111+
var backend = new http.Backend(value[i]);
112+
this.backends.push(backend);
113+
}
114+
}
115+
// others
116+
else if (typeof (key) == "string" && typeof (this[key]) == typeof (value)) {
88117
this[key] = value;
89118
}
90119
}
91120
}
121+
122+
this.findBackend = function (backendId) {
123+
for (var i = 0; i < this.backends.length; i++) {
124+
if (this.backends[i].id == backendId) {
125+
return this.backends[i];
126+
}
127+
}
128+
129+
return null;
130+
};
92131
};
93132

94133
http.Fastcgi = function (options) {

0 commit comments

Comments
 (0)