aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app.coffee20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/app.coffee b/src/app.coffee
index df3c0433..fc1eee37 100644
--- a/src/app.coffee
+++ b/src/app.coffee
@@ -6,6 +6,7 @@ path = require('path')
passport = require('./passport')
config = require('./config')
fs = require('fs')
+proxyMiddleware = require('http-proxy-middleware')
sessions = require("./routes/sessions")(passport)
transactions = require("./routes/transactions")
@@ -15,12 +16,25 @@ session = require('express-session')
RedisStore = require('connect-redis')(session)
sessionStore = new RedisStore(require('./redis').host, ttl: 172800)
+proxyContext = '/blockcypher'
+proxyOptions =
+ target: 'https://api.blockcypher.com'
+ changeOrigin: true
+ pathRewrite:
+ '^/blockcypher/': '/'
+ onProxyReq: (proxyReq, req, res) ->
+ symbol = if '?' in proxyReq.path then '&' else '?'
+ proxyReq.path += "#{symbol}token=#{config.blockcypher_token}"
+
+proxy = proxyMiddleware(proxyContext, proxyOptions)
+
app = express()
app.enable('trust proxy')
app.engine('html', require('hogan-express'))
app.set('view engine', 'html')
app.set('views', __dirname + '/views')
app.use(express.static(__dirname + '/public'))
+app.use(proxy)
app.use(bodyParser.urlencoded({ extended: true}))
app.use(bodyParser.json())
app.use(bodyParser.json({ type: 'application/vnd.api+json' }))
@@ -61,6 +75,7 @@ do fetchRates = ->
)
setTimeout(fetchRates, 120000)
+
app.get('/', cache, sessions.new)
app.get('/address', cache, (req, res) ->
@@ -91,11 +106,6 @@ app.get('/ticker', cache, (req, res) ->
)
)
-app.get('/token', cache, (req, res) ->
- res.write(config.blockcypher_token)
- res.end()
-)
-
app.get('/tips', cache, (req, res) ->
res.render('tips',
notice: true,