-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·51 lines (42 loc) · 1.37 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
var express = require('express'),
app = express(),
request = require('request'),
qs = require('querystring'),
path = require('path'),
bodyParser = require('body-parser');
var key = 'MDoyMjUzOWY0OC1lMDViLTExZTctYmE5MS1iNzI0MThmYjg5ZTI6WVcyZDVTYWNiUzdhS0tJVVNoWmdCazc1NmZiMExCZFFoQnZX';
if (!key) {
throw new Error(
"You must register and specify your own 'Backend / Server' type LCBO API Key. Keys can be attained from: https://lcboapi.com/"
);
}
var expressRouter = function() {
var router = express.Router();
router.get('/items', function(req, res, next) {
var options = {
url: 'https://lcboapi.com/products',
qs: req.query,
headers: {
Authorization: 'Token token="' + key + '"',
},
};
request.get(options, function(err, response, data) {
if (err) {
return res.status(500).send();
}
return res.json(JSON.parse(data));
});
});
return router;
};
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
app.use('/api', expressRouter());
app.listen(1337, function() {
console.log('LCBO Proxy Server listening on port 1337, test using: http://localhost:1337/api/items');
});