Last active
June 28, 2018 14:53
-
-
Save tomek-f/f8f431953ade4118511c978c8935d353 to your computer and use it in GitHub Desktop.
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 request = require('request'); | |
const { | |
PROXIED_HOST: proxiedHost = 'https://tomekf.pl', | |
PROXY_PORT: proxyPort = 1337, | |
LOCAL_PORT: localPort = 8000, | |
LOCAL_HOST: localHost = 'http://localhost', | |
} = process.env; | |
console.log(`proxy for ${proxiedHost} running on http://localhost:${proxyPort}`); | |
express() | |
.use(function (req, res, next) { | |
res.header("Access-Control-Allow-Origin", `${localHost}:${localPort}`); | |
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); | |
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS"); | |
next(); | |
}) | |
.use('/', (req, res) => { | |
req.pipe(request(`${proxiedHost}${req.url}`)).pipe(res); | |
}) | |
.listen(proxyPort); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment