Created
October 27, 2017 00:12
-
-
Save pjkelly/a73072b8279825e7cb312c856254bdaf to your computer and use it in GitHub Desktop.
Sample express app that acts as a proxy with CORS support.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const cors = require('cors'); | |
const proxy = require('http-proxy-middleware'); | |
const app = express(); | |
const port = process.env.PORT || 8080; | |
const onProxyReq = function (proxyReq, req, res) { | |
proxyReq.setHeader('Authorization', 'Basic SECRET'); | |
}; | |
const apiProxy = proxy('**', { | |
target: 'THE_URL_YOU_ARE_PROXYING_TO', | |
changeOrigin: true, // for vhosted sites | |
onProxyReq: onProxyReq | |
}); | |
app.use(cors()); | |
app.use(apiProxy); | |
app.listen(port, function() { | |
console.log('Proxy app is running on http://localhost:' + port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment