Skip to content

Instantly share code, notes, and snippets.

@paulRbr
Forked from ArnaudD/Procfile
Last active August 29, 2015 14:05
Show Gist options
  • Save paulRbr/af1c94437914078d41f2 to your computer and use it in GitHub Desktop.
Save paulRbr/af1c94437914078d41f2 to your computer and use it in GitHub Desktop.
npm install
git push heroku master
var express = require('express')
var app = express();
var proxy = require('proxy-middleware');
var url = require('url');
app.set('port', (process.env.PORT || 5000))
app.get('/', function(request, response) {
response.send('Hello World!')
})
app.all('/*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "http://assets.domain.com");
res.header("Access-Control-Allow-Credentials", "true");
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header("Access-Control-Allow-Headers", req.headers["access-control-request-headers"]);
// intercept OPTIONS method
if ('OPTIONS' == req.method) {
res.send(200);
}
else {
req.headers['origin'] = 'https://back.domain.com';
req.headers['referer'] = 'https://back.domain.com';
next();
}
});
app.use('/api', proxy(url.parse('https://back.domain.com/api')));
app.listen(app.get('port'), function() {
console.log("Node app is running at localhost:" + app.get('port'))
})
{
"name": "proxy-server",
"version": "0.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"connect": "^3.1.1",
"express": "~3.4.x",
"proxy-middleware": "^0.5.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
web: node index.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment