Skip to content

Instantly share code, notes, and snippets.

@tomek-f
Last active June 28, 2018 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomek-f/f8f431953ade4118511c978c8935d353 to your computer and use it in GitHub Desktop.
Save tomek-f/f8f431953ade4118511c978c8935d353 to your computer and use it in GitHub Desktop.
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