npm install
git push heroku master
-
-
Save ArnaudD/d776b692b5f1ee64257e to your computer and use it in GitHub Desktop.
ClicRDV Proxy on Heroku
This file contains hidden or 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://run.plnkr.co"); | |
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://www.clicrdv.com'; | |
req.headers['referer'] = 'https://www.clicrdv.com'; | |
next(); | |
} | |
}); | |
app.use('/api', proxy(url.parse('https://www.clicrdv.com/api'))); | |
app.use('/pro', proxy(url.parse('https://www.clicrdv.com/pro'))); | |
app.listen(app.get('port'), function() { | |
console.log("Node app is running at localhost:" + app.get('port')) | |
}) |
This file contains hidden or 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": "peaceful-coast-9239", | |
"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 hidden or 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