-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
110 lines (90 loc) · 2.79 KB
/
app.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var express = require("express");
var path = require("path");
var logger = require("morgan");
var axios = require("axios");
var app = express();
app.listen(3030);
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
/* Register this node with the Proxeus server */
let error = null;
const nodeId = "dribdat";
const name = "Dribdat Application";
const description = "Hello world";
const serviceUrl = "http://localhost:3030";
const jwtSecret = "ABCDE1234567";
const proxeusUrl = "http://localhost:1323";
let ExternalNode = {
ID: nodeId, // {dribdat.username}
Name: name,
Detail: description,
Url: serviceUrl,
Secret: jwtSecret,
}
console.log("Attempting to connect to Proxeus", proxeusUrl);
const url = proxeusUrl + "/api/admin/external/register"
axios.post(url, {
url: url,
headers: {
"Content-Type": "application/json",
},
})
.then(data => {
if (data.status == 200) {
console.log("Node was registered", name);
} else {
console.error("Error registering Node", name);
}
})
.catch(err => {
console.error("Error registering Node", name);
});
// * GET `/health` heartbeat to check that the node is alive.
app.get('/health', async (req, res) => {
console.log('Health Request Type:', req.method)
});
// * GET `/node/:id/config` return the configuraton HTML page for the given node instance.
app.get('/node/:id/config', async (req, res) => {
const nodeId = request.params.id;
console.log('Get the Config for ID:', nodeId)
});
// * POST `/node/:id/config` updated the configuration of the node instance with the give id.
app.post('/node/:id/config', async (req, res) => {
const nodeId = request.params.id;
console.log('Save the Config for ID:', nodeId)
});
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// * POST `/node/:id/next` trigger the execution of a node instance.
app.post('/node/:id/next', async (req, res) => {
const nodeId = request.params.id;
console.log('Save the Config for ID:', nodeId)
//
axios.get("https://aareguru.existenz.ch/today?app=my.app.ch&version=1.0.42")
.then(data => {
if (data.status != 200) {
console.error("Error talking to Dribdat");
}
/*
{
"aare": 22.1,
"text": "Spaghettiwasser",
"time": 1692627000
}
*/
res.send(data)
})
.catch(err => {
res.send(err)
});
});
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// * POST `/node/:id/remove` remove a node instance, called when a node instance is removed from a workflow definition.
app.post('/node/:id/remove', async (req, res) => {
const nodeId = request.params.id;
console.log('Save the Config for ID:', nodeId)
});
console.log(
"Hello, world! App is running on http://localhost:3030"
);
module.exports = app;