Improved demo, optimized server.js for Heroku

This commit is contained in:
Rob W
2013-01-04 23:18:38 +01:00
parent 051858b480
commit 098f425d0a
2 changed files with 23 additions and 7 deletions

View File

@@ -48,11 +48,11 @@ textarea {
<div id="top">
CORS Anywhere demo &bull; <a href="https://github.com/Rob--W/cors-anywhere/">Github</a> &bull; <a href="http://cors-anywhere.herokuapp.com">Live server</a>.
<label>
Url to be fetched
<input type="url" id="url">
Url to be fetched (example: <a href="//rob.lekensteyn.nl/dump.php">rob.lekensteyn.nl/dump.php</a>)
<input type="url" id="url" value="">
</label>
<label>
If using POST, enter the data:
If using POST, enter the data:
<input type="text" id="data">
</label>
<label>
@@ -77,7 +77,7 @@ textarea {
doCORSRequest({
method: 'GET',
url: url,
success: success,
success: options.success,
error: options.error
});
} else {
@@ -100,7 +100,8 @@ textarea {
var urlField = document.getElementById('url');
var dataField = document.getElementById('data');
var outputField = document.getElementById('output');
document.getElementById('get').onclick = function() {
document.getElementById('get').onclick = function(e) {
e.preventDefault();
doCORSRequest({
method: 'GET',
url: urlField.value,
@@ -108,7 +109,8 @@ textarea {
error: onError
});
};
document.getElementById('post').onclick = function() {
document.getElementById('post').onclick = function(e) {
e.preventDefault();
doCORSRequest({
method: 'POST',
url: urlField.value,

View File

@@ -5,7 +5,21 @@ var port = process.env.PORT || 8080;
var cors_proxy = require("./lib/cors-anywhere");
cors_proxy.createServer({
requireHeader: 'x-requested-with',
removeHeaders: ['cookie', 'cookie2']
removeHeaders: [
'cookie',
'cookie2',
// Strip Heroku-specific headers
'x-heroku-queue-wait-time',
'x-heroku-queue-depth',
'x-heroku-dynos-in-use',
'x-request-start'
],
httpProxyOptions: {
enable: {
// Do not add X-Forwarded-For, etc. headers, because Heroku already adds it.
xforward: false
}
}
}).listen(port, host, function() {
console.log('Running CORS Anywhere on ' + host + ':' + port);
});