-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (34 loc) · 1.41 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
const express = require('express');
const app = express();
const request = require('request');
const cors = require('cors')
var parseString = require('xml2js').parseString;
app.use(cors({ origin: "*" }));
app.use(express.static(__dirname + '/dist/bibVirtualKeyboard'));
app.listen(process.env.PORT || 8080);
app.route('/api/:search').get((req, res) => {
var url = 'http://gent.staging.aquabrowser.be/api/v1/search/?q=' + req.params['search'] + '&authorization=' + process.env.API_KEY + '&branch=Oost-Vlaanderen/Gent/Hoofdbibliotheek';
request.get(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
parseString(body, function (err, result) {
res.send(result);
});
} else {
console.log(error);
}
});
});
app.route('/api/availability/:frabl').get((req, res) => {
var url = 'http://gent.staging.aquabrowser.be/api/v1/availability/?frabl=' + req.params['frabl'] + '&authorization=' + process.env.API_KEY + '&branch=Oost-Vlaanderen/Gent/Hoofdbibliotheek';
request.get(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
// console.log("call ontvangen");
// console.log(body);
parseString(body, function (err, result) {
res.send(result);
});
} else {
console.log(error)
}
});
});