npm install
git push heroku master
-
-
Save paulRbr/af1c94437914078d41f2 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
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')) | |
}) |
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
{ | |
"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" | |
} |
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
web: node index.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment