Created
March 25, 2019 07:58
-
-
Save davidgg/adbac223fecd8d0ab2f64ff3b20fcadf to your computer and use it in GitHub Desktop.
Express proxy server
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
// Avoid CORS issues using a local proxy server | |
const express = require('express'); | |
const request = require('request'); | |
const cors = require('cors'); | |
const app = express(); | |
const url = 'http://sample.com'; | |
app.use(cors()); | |
app.use('/', function(req, res) { | |
const url = url + req.url; | |
req.pipe(request(url)).pipe(res); | |
}); | |
app.listen(process.env.PORT || 3001); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment