metamaps--metamaps/apiProxyMiddleware.js
2018-03-05 09:53:45 -05:00

22 lines
No EOL
583 B
JavaScript

const request = require('request')
function apiProxyMiddleware (req, res, next) {
if (!(req.xhr || req.originalUrl.indexOf('.json') > -1)) {
return next()
}
console.log('xhr request', req.originalUrl)
const method = req.method.toLowerCase()
req.pipe(
request[method](process.env.API + req.originalUrl, {
headers: {
...req.headers,
host: process.env.API
},
followRedirect: false
})
)
.on('error', console.log)
.pipe(res)
}
module.exports = apiProxyMiddleware