-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
62 lines (58 loc) · 1.97 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Provide an event that contains an array of objects with the following keys:
*
* - mode: type of routing. It can be either `path` or `host`.
* In `path` mode, the URL path is used to determine which backend to forward the request to.
* In `host` mode, the HTTP host header is used to determine which backend to forward the request to.
* Defaults to `host` mode.
* - name: name of cluster the servers will be grouped within.
* - predicate: value used along with mode to determine which cluster the request will be forwarded to.
* `path` mode example: `acl <cluster> url_beg /<predicate>`.
* `host` mode example: `acl <cluster> hdr(host) -i <predicate>`.
* - cookie: name of cookie to be used for sticky sessions. If not defined, sticky sessions will not be configured.
* - servers: key-value pairs of server names and their corresponding IP addresses.
*
* Example:
* =======
* [
* {
* "mode": "host",
* "name": "example",
* "predicate": "example.com",
* "cookie": "JSESSIONID",
* "servers": [
* {
* "name": "app1",
* "ip" : "192.168.1.5:80"
* },
* {
* "name": "app2",
* "ip" : "192.168.1.7:80"
* }
* ]
* },
* {
* "mode": "path",
* "name": "multiservice",
* "predicate": "service",
* "servers": [
* {
* "name": "service1",
* "ip" : "10.0.0.5:80"
* },
* {
* "name": "service2",
* "ip" : "10.0.0.6:80"
* }
* ]
* }
* ]
*
*/
exports.handler = (event, context, callback) => {
console.log('Received event:', JSON.stringify(event, null, 2))
const nunjucks = require('nunjucks')
nunjucks.configure('template', { autoescape: true })
const computedConfig = nunjucks.render('haproxy.cfg.njk', {clusters: event})
context.done(null, computedConfig)
}