-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
52 lines (42 loc) · 1.51 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
const express = require('express');
const bodyParser = require('body-parser')
const app = express();
let request = require('request');
var crypto = require('crypto');
// load web app
app.use('/src', express.static(__dirname + '/src'));
//app.use(express.static(path.join(__dirname, 'build')));
app.use(express.static('src'));
app.use(bodyParser());
//var kongUrl = "https://developer.firstdata.com/api";
const fs = require('fs');
let rawdata = fs.readFileSync('credentials.json');
let credentials = JSON.parse(rawdata)['dev'];
// Set the headers
var getAuthenticationHeaders = function () {
var date = new Date().toUTCString();
var stringToSign = 'date: ' + date.trim();
var encodedSignature = crypto.createHmac("sha1", credentials.secret).update(stringToSign).digest("base64");
var hmacAuth = 'hmac username="' + credentials.username + '",algorithm="hmac-sha1",headers="date",signature="' + encodedSignature + '"';
return {
'date': date,
'Authorization': hmacAuth
}
}
app.all('/marketplace/*', function(req, res) {
var options = {
method: req.method,
url: credentials.kongUrl + req.originalUrl,
headers: getAuthenticationHeaders()
};
if (req.method == 'POST') {
options['json'] = req.body;
options['content-type'] = 'application/json';
}
request(options, function(error, response, body) {
debugger;
if (error) throw new Error(error);
res.status(response.statusCode).send(body);
});
});
app.listen(process.env.PORT || 8080);