tg-redbird 1.2.0-rc → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -27
- package/index.js +0 -1
- package/package.json +1 -2
- package/lib/etcd-backend.js +0 -90
package/README.md
CHANGED
@@ -274,33 +274,6 @@ docker(redbird).register("stable.api.com", 'company/api:v2.*');
|
|
274
274
|
docker(redbird).register("preview.api.com", 'company/api:v[3-9].*');
|
275
275
|
```
|
276
276
|
|
277
|
-
## etcd backend
|
278
|
-
Redbird can use [node-etcd](https://github.com/stianeikeland/node-etcd) to automatically create proxy records from an etcd cluster. Configuration
|
279
|
-
is accomplished by passing an array of [options](https://github.com/stianeikeland/node-etcd#constructor-options), plus the hosts and path variables,
|
280
|
-
which define which etcd cluster hosts, and which directory within those hosts, that Redbird should poll for updates.
|
281
|
-
|
282
|
-
```js
|
283
|
-
var redbird = require('redbird')({
|
284
|
-
port:8080
|
285
|
-
});
|
286
|
-
|
287
|
-
var options = {
|
288
|
-
hosts: ['localhost:2379'], // REQUIRED - you must define array of cluster hosts
|
289
|
-
path: ['redbird'], // OPTIONAL - path to etcd keys
|
290
|
-
... // OPTIONAL - pass in node-etcd connection options
|
291
|
-
}
|
292
|
-
require('redbird').etcd(redbird,options);
|
293
|
-
```
|
294
|
-
etcd records can be created in one of two ways, either as a target destination pair:
|
295
|
-
```/redbird/example.com "8.8.8.8"```
|
296
|
-
or by passing a JSON object containing multiple hosts, and Redbird options:
|
297
|
-
```
|
298
|
-
/redbird/derek.com { "hosts" : ["10.10.10.10", "11.11.11.11"]}
|
299
|
-
/redbird/johnathan.com { "ssl" : true }
|
300
|
-
/redbird/jeff.com { "docker" : "alpine/alpine:latest" }
|
301
|
-
```
|
302
|
-
|
303
|
-
|
304
277
|
## Cluster support
|
305
278
|
Redbird supports automatic node cluster generation. To use, just specify the number
|
306
279
|
of processes that you want Redbird to use in the options object. Redbird will automatically
|
package/index.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "tg-redbird",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.3.0",
|
4
4
|
"description": "A reverse proxy with support for dynamic tables",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
@@ -36,7 +36,6 @@
|
|
36
36
|
"le-store-certbot": "^2.2.3",
|
37
37
|
"lodash": "^4.17.15",
|
38
38
|
"lru-cache": "^5.1.1",
|
39
|
-
"node-etcd": "^7.0.0",
|
40
39
|
"object-hash": "^1.3.1",
|
41
40
|
"pino": "^5.15.0",
|
42
41
|
"safetimeout": "^0.1.2",
|
package/lib/etcd-backend.js
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
/*eslint-env node */
|
2
|
-
'use strict';
|
3
|
-
|
4
|
-
/**
|
5
|
-
Redbird ETCD Module
|
6
|
-
This module handles automatic proxy registration via etcd
|
7
|
-
*/
|
8
|
-
var Etcd = require('node-etcd');
|
9
|
-
|
10
|
-
function ETCDModule(redbird, options) {
|
11
|
-
if (!(this instanceof ETCDModule)) {
|
12
|
-
return new ETCDModule(redbird, options);
|
13
|
-
}
|
14
|
-
|
15
|
-
// Create Redbird Instance and Log
|
16
|
-
this.redbird = redbird;
|
17
|
-
var log = redbird.log;
|
18
|
-
var _this = this;
|
19
|
-
|
20
|
-
// Create node-etcd Instance
|
21
|
-
this.etcd = new Etcd(options.hosts, options.ssloptions);
|
22
|
-
this.etcd_dir = typeof options.path !== 'undefined' ? options.path : 'redbird';
|
23
|
-
|
24
|
-
// Create directory if not created
|
25
|
-
this.etcd.get(this.etcd_dir, function (err, body, header) {
|
26
|
-
if (err && err.errorCode == 100) {
|
27
|
-
_this.etcd.mkdir(_this.etcd_dir, function (err) {
|
28
|
-
if (err) {
|
29
|
-
log.error(err, 'etcd backend error');
|
30
|
-
} else {
|
31
|
-
createWatcher();
|
32
|
-
}
|
33
|
-
});
|
34
|
-
} else if (!err && body.node.dir) {
|
35
|
-
createWatcher();
|
36
|
-
} else {
|
37
|
-
log.error(err, 'etcd backend error');
|
38
|
-
}
|
39
|
-
});
|
40
|
-
|
41
|
-
// Helper function to check if values contain settings
|
42
|
-
function IsJsonString(str) {
|
43
|
-
try {
|
44
|
-
JSON.parse(str);
|
45
|
-
} catch (e) {
|
46
|
-
return false;
|
47
|
-
}
|
48
|
-
return true;
|
49
|
-
}
|
50
|
-
|
51
|
-
// Helper function to pretify etcd directory strings
|
52
|
-
function removeEtcDir(str) {
|
53
|
-
return str.replace(_this.etcd_dir, '').replace(/^\/+|\/+$/g, '');
|
54
|
-
}
|
55
|
-
|
56
|
-
function createWatcher() {
|
57
|
-
// Watch etcd directory
|
58
|
-
_this.watcher = _this.etcd.watcher(_this.etcd_dir, null, { recursive: true });
|
59
|
-
|
60
|
-
// On Add/Update
|
61
|
-
_this.watcher.on('change', function (body, headers) {
|
62
|
-
if (body.node.key && body.node.value && !IsJsonString(body.node.value)) {
|
63
|
-
_this.redbird.register(removeEtcDir(body.node.key), body.node.value);
|
64
|
-
} else if (body.node.key && body.node.value && IsJsonString(body.node.value)) {
|
65
|
-
var config = JSON.parse(body.node.value);
|
66
|
-
if (typeof config.docker !== 'undefined') {
|
67
|
-
require('../')
|
68
|
-
.docker(_this.redbird)
|
69
|
-
.register(body.node.key, body.node.value.docker, body.node.value);
|
70
|
-
} else {
|
71
|
-
_this.redbird.register(removeEtcDir(body.node.key), config.hosts, config);
|
72
|
-
}
|
73
|
-
}
|
74
|
-
});
|
75
|
-
|
76
|
-
// On Delete
|
77
|
-
_this.watcher.on('delete', function (body, headers) {
|
78
|
-
if (body.node.key) {
|
79
|
-
_this.redbird.unregister(removeEtcDir(body.node.key));
|
80
|
-
}
|
81
|
-
});
|
82
|
-
|
83
|
-
// Handle Errors
|
84
|
-
_this.watcher.on('error', function (err) {
|
85
|
-
log.error(err, 'etcd backend error');
|
86
|
-
});
|
87
|
-
}
|
88
|
-
}
|
89
|
-
|
90
|
-
module.exports = ETCDModule;
|