-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex_disp_res_browser.js
More file actions
70 lines (64 loc) · 1.92 KB
/
index_disp_res_browser.js
File metadata and controls
70 lines (64 loc) · 1.92 KB
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
const PORT = process.env.PORT || 8005;
const crypto = require('crypto');
const fetch = require('node-fetch');
var request = require('request');
var express = require('express')
, cors = require('cors'),
favicon = require('serve-favicon')
, app = express();
var bodyParser = require('body-parser');
app.use(cors());
var path = require("path");
app.set('port', PORT);
app.listen(app.get('port'));
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json());
console.log("Server is running at " + PORT);
var res = '';
//Function to call lambda service as of now input is hardcoded
function callLambdaService(userKey,accounttype,callback) {
//To check whether accountType is empty or null or undefined
if(!accounttype || /^\s*$/.test(accounttype)){
var options = {
uri : 'https://hu4xwdeme9.execute-api.us-east-1.amazonaws.com/DEV/bankingbot/accountsummary?userKey='+userKey,
method : 'GET'
};
request(options, function (error, response, body) {
console.log(response);
if (!error && response.statusCode == 200) {
res = body;
}
else {
res = 'Not Found';
}
callback(res);
});
}
else
{
var options = {
uri : 'https://hu4xwdeme9.execute-api.us-east-1.amazonaws.com/DEV/bankingbot/accountsummary?userKey='+userKey+'&accountType='+accounttype,
method : 'GET'
};
request(options, function (error, response, body) {
console.log(response);
if (!error && response.statusCode == 200) {
res = body;
}
else {
res = 'Not Found';
}
callback(res);
});
}
}
//Call a method which hits the aws url and get the response back
callLambdaService("1001","CHECKING", function(resp){
//Hurray Got response ..Now convert this to string
body=JSON.stringify(resp);;
});
//To check the response in browser
//app.get('/',function(req,res){
//Send this response to browser
// res.send(body);
//});