-
Notifications
You must be signed in to change notification settings - Fork 1
/
init-kong.js
59 lines (55 loc) · 1.94 KB
/
init-kong.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
const fetch = require('node-fetch');
const data = require("./config").default;
data.forEach(
async elem => {
let service = elem.service;
let routes = elem.routes;
let plugins = elem.plugins;
await fetch('http://kong:8001/services', {
method: 'POST', // or 'PUT'
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(service),
})
.then(response => response.json())
.then(data => {
console.log('Service successfully created:', data);
})
.catch((error) => {
console.error('Error on service creation:', error);
});
routes.forEach(route => {
fetch(`http://kong:8001/services/${service.name}/routes`, {
method: 'POST', // or 'PUT'
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(route)
})
.then(response => response.json())
.then(data => {
console.log('Route successfully created:', data);
})
.catch((error) => {
console.error('Error on route creation:', error);
});
});
plugins.forEach(plugin => {
fetch(`http://kong:8001/services/${service.name}/plugins`, {
method: 'POST', // or 'PUT'
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(plugin)
})
.then(response => response.json())
.then(data => {
console.log('Plugin successfully created:', data);
})
.catch((error) => {
console.error('Error on plugin creation:', error);
});
});
}
);