aboutsummaryrefslogtreecommitdiffstats
path: root/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'app.js')
-rw-r--r--app.js29
1 files changed, 23 insertions, 6 deletions
diff --git a/app.js b/app.js
index 33098305..a84e945a 100644
--- a/app.js
+++ b/app.js
@@ -1,5 +1,6 @@
(function() {
- var RedisStore, app, authorize, bodyParser, cache, config, cookieParser, express, fetchRates, fs, passport, path, request, session, sessionStore, sessions, transactions, users;
+ var RedisStore, app, authorize, bodyParser, cache, config, cookieParser, express, fetchRates, fs, passport, path, proxy, proxyContext, proxyMiddleware, proxyOptions, request, session, sessionStore, sessions, transactions, users,
+ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
request = require('request');
@@ -17,6 +18,8 @@
fs = require('fs');
+ proxyMiddleware = require('http-proxy-middleware');
+
sessions = require("./routes/sessions")(passport);
transactions = require("./routes/transactions");
@@ -31,6 +34,23 @@
ttl: 172800
});
+ proxyContext = '/blockcypher';
+
+ proxyOptions = {
+ target: 'https://api.blockcypher.com',
+ changeOrigin: true,
+ pathRewrite: {
+ '^/blockcypher/': '/'
+ },
+ onProxyReq: function(proxyReq, req, res) {
+ var symbol;
+ symbol = __indexOf.call(proxyReq.path, '?') >= 0 ? '&' : '?';
+ return proxyReq.path += "" + symbol + "token=" + config.blockcypher_token;
+ }
+ };
+
+ proxy = proxyMiddleware(proxyContext, proxyOptions);
+
app = express();
app.enable('trust proxy');
@@ -43,6 +63,8 @@
app.use(express["static"](__dirname + '/public'));
+ app.use(proxy);
+
app.use(bodyParser.urlencoded({
extended: true
}));
@@ -137,11 +159,6 @@
});
});
- app.get('/token', cache, function(req, res) {
- res.write(config.blockcypher_token);
- return res.end();
- });
-
app.get('/tips', cache, function(req, res) {
return res.render('tips', {
notice: true,