-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
89 lines (67 loc) · 2.81 KB
/
server.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
// Dashboard RRF server.js
const express = require('express');
//const { parser, fsm } = require('./src/lib/api');
//const fsm = require('./lib/fsm').fsm;
//const parser = require('./lib/parser').default;
var { fsms, sses } = require('./src/lib/sse');
const salons = require('./src/lib/salons');
var proxy = require('http-proxy-middleware');
const liste = require('./Noeuds.json');
const SALONS = require('./config').SALONS;
const CARTO = require('./config').CARTO;
const port = process.env.PORT || require('./config').PORT;
var server = express();
//var sseInit = () => {};
function testLocal(req, res, next) {
// if there is no file name, skip to the next route
//console.log("testLocal - name : ",req.params.name);
if (salons[req.params.name].file === '') {
next('route')
}
// otherwise pass the control to the next middleware function in this stack
else {
//sseInit = sses[req.params.name].init;
next();
}
}
server.use(express.static('client/build'));
server.get('/api/svxlink/:name', testLocal, function(req, res, next){
res.status(200).send(fsms[req.params.name])
})
server.get('/api/svxlink/:name', proxy({ target: 'http://', router: function(req){return salons[req.params.name].url}, pathRewrite: function(path, req){return salons[req.params.name].api}, changeOrigin: true }))
server.get('/realtime/:name', testLocal, function(req, res){ sses[req.params.name].init(req, res); } )
server.get('/realtime/:name', proxy({ target: 'http://', router: function(req, res){return salons[req.params.name].url}, pathRewrite: function(path, req){return salons[req.params.name].stream}, changeOrigin: true }))
server.get('/audiostream/:name', proxy({ target: 'http://', router: function(req, res){return salons[req.params.name].audioUrl}, pathRewrite: function(path, req){return salons[req.params.name].audioStream}, changeOrigin: true }))
server.get('/allstar', proxy({target: 'http://www.ve2csc.com', pathRewrite:{'/allstar' : '/nodes/nodes.aspx?pswd=rrf'}, changeOrigin: true}))
server.get('/infoNodes', (req, res) => {
res.json({data: node})
})
server.get('/salons', (req, res) => {
var slns= [];
SALONS.forEach( sl => {
slns.push(sl.name)
})
res.json({ data: slns } )
})
server.get('/salons&dtmf', (req, res) => {
var slns= [];
SALONS.forEach( sl => {
slns.push({name:sl.name, dtmf:sl.dtmf})
})
res.json({ data: slns } )
})
server.get('/carto', (req, res) => {
res.json({ data: CARTO } )
})
server.get('/liste', (req, res) => {
res.json( liste)
})
// console.log that your server is up and running
server.listen(port, () => console.log(`Listening on port ${port}`));
// create a GET route
server.get('/express_backend', (req, res) => {
res.send({ express: 'YOUR EXPRESS BACKEND IS CONNECTED TO REACT' });
});
server.get('/noeuds', (req, res) => {
res.send({ test: 'test backend ' });
});