-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
129 lines (124 loc) · 4.55 KB
/
index.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
'use strict';
const express = require('express');
const bodyParser = require('body-parser');
const moment = require('moment');
const plaid = require('plaid');
const dotenv = require('dotenv');
const morgan = require('morgan');
const nodemon = require('nodemon');
require('dotenv').config();
const APP_PORT = process.env.APP_PORT
const PLAID_CLIENT_ID = process.env.PLAID_CLIENT_ID
const PLAID_SECRET = process.env.PLAID_SECRET
const PLAID_PUBLIC_KEY = process.env.PLAID_PUBLIC_KEY
const PLAID_ENV = process.env.PLAID_ENV
// We store the access_token in memory - in production, store it in a secure
// persistent data store
const ACCESS_TOKEN = null;
const PUBLIC_TOKEN = null;
// Initialize the Plaid client
// const client = new plaid.Client(
// PLAID_CLIENT_ID,
// PLAID_SECRET,
// PLAID_PUBLIC_KEY,
// plaid.environments[PLAID_ENV]
// );
//
const app = express();
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(morgan('dev'));
app.use('/', require('./resources'));
//
// app.get('/', function(request, response, next) {
// response.render('index.ejs', {
// PLAID_PUBLIC_KEY: PLAID_PUBLIC_KEY,
// PLAID_ENV: PLAID_ENV,
// });
// });
//
// app.post('/get_access_token', function(request, response, next) {
// PUBLIC_TOKEN = request.body.public_token;
// client.exchangePublicToken(PUBLIC_TOKEN, function(error, tokenResponse) {
// if (error != null) {
// let msg = 'Could not exchange public_token!';
// console.log(msg + '\n' + error);
// return response.json({error: msg});
// }
// ACCESS_TOKEN = tokenResponse.access_token;
// console.log('Access Token: ' + ACCESS_TOKEN);
// response.json({'error': false});
// });
// });
//
// app.post('/set_access_token', function(request, response, next) {
// ACCESS_TOKEN = request.body.access_token;
// console.log('Access Token: ' + ACCESS_TOKEN);
// response.json({'error': false});
// });
//
// app.get('/accounts', function(request, response, next) {
// // Retrieve high-level account information and account and routing numbers
// // for each account associated with the Item.
// client.getAuth(ACCESS_TOKEN, function(error, authResponse) {
// if(error != null) {
// let msg = 'Unable to pull accounts from the Plaid API.';
// console.log(msg + '\n' + error);
// return response.json({error: msg});
// }
//
// console.log(authResponse.accounts);
// response.json({
// error: false,
// accounts: authResponse.accounts,
// numbers: authResponse.numbers,
// });
// });
// });
//
// app.post('/item', function(request, response, next) {
// // Pull the Item - this includes information about available products,
// // billed products, webhook information, and more.
// client.getItem(ACCESS_TOKEN, function(error, itemResponse) {
// if (error != null) {
// console.log(JSON.stringify(error));
// return response.json({error: error});
// }
//
// // Also pull information about the institution
// client.getInstitutionById(itemResponse.item.institution_id, function(err, instRes) {
// if (err != null) {
// let msg = 'Unable to pull institution information from the Plaid API.';
// console.log(msg + '\n' + error);
// return response.json({error: msg});
// } else {
// response.json({
// item: itemResponse.item,
// institution: instRes.institution,
// });
// }
// });
// });
// });
//
// app.post('/transactions', function(request, response, next) {
// // Pull transactions for the Item for the last 30 days
// let startDate = moment().subtract(30, 'days').format('YYYY-MM-DD');
// let endDate = moment().format('YYYY-MM-DD');
// client.getTransactions(ACCESS_TOKEN, startDate, endDate, {
// count: 250,
// offset: 0,
// }, function(error, transactionsResponse) {
// if (error != null) {
// console.log(JSON.stringify(error));
// return response.json({error: error});
// }
// console.log('pulled ' + transactionsResponse.transactions.length + ' transactions');
// response.json(transactionsResponse);
// });
// });
//
const server = app.listen(process.env.APP_PORT, function () {
console.log(`soft-shell tacos on ${process.env.APP_PORT}`);
});