Permalink
Browse files

Enforce a consistent coding style using eslint

  • Loading branch information...
Rob--W committed Feb 26, 2016
1 parent e8f0e64 commit 0872577729fd858652b18835131d758857b4fc7e
Showing with 96 additions and 70 deletions.
  1. +28 −0 .eslintrc
  2. +0 −7 .jshintrc
  3. +18 −19 lib/cors-anywhere.js
  4. +2 −0 lib/regexp-top-level-domain.js
  5. +12 −10 package.json
  6. +16 −16 server.js
  7. +8 −8 test/setup.js
  8. +1 −0 test/test-memory.js
  9. +11 −10 test/test.js
@@ -0,0 +1,28 @@
{
"env": {
"node": true
},
"rules": {
"array-bracket-spacing": [2, "never"],
"block-scoped-var": 2,
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
"comma-dangle": [2, "always-multiline"],
"computed-property-spacing": [2, "never"],
"curly": 2,
"eol-last": 2,
"eqeqeq": [2, "smart"],
"max-len": [1, 125],
"new-cap": 1,
"no-extend-native": 2,
"no-mixed-spaces-and-tabs": 2,
"no-trailing-spaces": 2,
"no-undef": 2,
"no-unused-vars": 1,
"no-use-before-define": [2, "nofunc"],
"object-curly-spacing": [2, "never"],
"quotes": [2, "single", "avoid-escape"],
"semi": [2, "always"],
"keyword-spacing": 2,
"space-unary-ops": 2
}
}

This file was deleted.

Oops, something went wrong.
@@ -104,11 +104,11 @@ function proxyRequest(req, res, proxy) {
/**
* "Allow observer to modify headers or abort response"
* https://github.com/nodejitsu/node-http-proxy/blob/v1.11.1/lib/http-proxy/passes/web-incoming.js#L147
*
*
* This method modifies the response headers of the proxied response.
* If a redirect is detected, the response is not sent to the client,
* and a new request is initiated.
*
*
* @param response {ClientRequest} The response of the proxied request
* @param req {IncomingMessage} Incoming HTTP request, augmented with property corsAnywhereRequestState
* @param req.corsAnywhereRequestState {object}
@@ -122,7 +122,6 @@ function proxyRequest(req, res, proxy) {
* @this {HttpProxy}
*/
function onProxyResponse(response, req, res) {
/* jshint validthis:true */
var proxy = this;
var requestState = req.corsAnywhereRequestState;
@@ -145,7 +144,7 @@ function onProxyResponse(response, req, res) {
// cancel redirects.
// Set header for debugging purposes. Do not try to parse it!
res.setHeader('X-CORS-Redirect-' + requestState.redirectCount_, statusCode + ' ' + locationHeader);
req.method = 'GET';
req.headers['content-length'] = '0';
delete req.headers['content-type'];
@@ -160,15 +159,15 @@ function onProxyResponse(response, req, res) {
res.setHeader = res.writeHead = function noop() {};
response.on = function noop2() {};
response.pipe = function(res) {
res.setHeader = setHeader;
res.writeHead = writeHead;
// Trigger proxyReq.abort() (this is not of any imporance, it's just used to stop wasting resources.)
// https://github.com/nodejitsu/node-http-proxy/blob/v1.11.1/lib/http-proxy/passes/web-incoming.js#L125-L128
req.emit('aborted');
// Remove all listeners (=reset events to initial state)
req.removeAllListeners();
// Initiate a new proxy request.
proxyRequest(req, res, proxy);
res.setHeader = setHeader;
res.writeHead = writeHead;
// Trigger proxyReq.abort() (this is not of any imporance, it's just used to stop wasting resources.)
// https://github.com/nodejitsu/node-http-proxy/blob/v1.11.1/lib/http-proxy/passes/web-incoming.js#L125-L128
req.emit('aborted');
// Remove all listeners (=reset events to initial state)
req.removeAllListeners();
// Initiate a new proxy request.
proxyRequest(req, res, proxy);
};
return;
}
@@ -200,12 +199,12 @@ function parseURL(req_url) {
return null;
}
if (!match[1]) {
// scheme is omitted.
// Scheme is omitted.
if (req_url.lastIndexOf('//', 0) === -1) {
// "//" is omitted.
req_url = '//' + req_url;
}
req_url = (match[4] == '443' ? 'https:' : 'http:') + req_url;
req_url = (match[4] === '443' ? 'https:' : 'http:') + req_url;
}
return url.parse(req_url);
}
@@ -219,7 +218,7 @@ var getHandler = exports.getHandler = function(options, proxy) {
originWhitelist: [], // If non-empty, requests not from an origin in this list will be blocked.
requireHeader: null, // Require a header to be set?
removeHeaders: [], // Strip these request headers.
setHeaders: {} // Set these request headers.
setHeaders: {}, // Set these request headers.
};
if (options) {
Object.keys(corsAnywhere).forEach(function(option) {
@@ -248,7 +247,7 @@ var getHandler = exports.getHandler = function(options, proxy) {
return function(req, res) {
var cors_headers = withCORS({}, req);
if (req.method == 'OPTIONS') {
if (req.method === 'OPTIONS') {
// Pre-flight request. Reply successfully:
res.writeHead(200, cors_headers);
res.end();
@@ -320,7 +319,7 @@ var getHandler = exports.getHandler = function(options, proxy) {
location: location,
getProxyForUrl: corsAnywhere.getProxyForUrl,
maxRedirects: corsAnywhere.maxRedirects,
proxyBaseUrl: proxyBaseUrl
proxyBaseUrl: proxyBaseUrl,
};
proxyRequest(req, res, proxy);
@@ -330,7 +329,7 @@ var getHandler = exports.getHandler = function(options, proxy) {
// Create server with default and given values
// Creator still needs to call .listen()
exports.createServer = function createServer(options) {
if (!options) options = {};
options = options || {};
// Default options:
var httpProxyOptions = {

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -1,23 +1,23 @@
{
"name": "cors-anywhere",
"version": "0.3.0",
"description": "CORS Anywhere is a reverse proxy which adds CORS headers to the proxied request. Request URL is taken from the path",
"description": "CORS Anywhere is a reverse proxy which adds CORS headers to the proxied request. Request URL is taken from the path",
"license": "MIT",
"author": "Rob Wu <rob@robwu.nl>",
"repository": {
"type": "git",
"url": "https://github.com/Rob--W/cors-anywhere.git"
"type": "git",
"url": "https://github.com/Rob--W/cors-anywhere.git"
},
"bugs": {
"url": "https://github.com/Rob--W/cors-anywhere/issues/",
"email": "rob@robwu.nl"
"url": "https://github.com/Rob--W/cors-anywhere/issues/",
"email": "rob@robwu.nl"
},
"keywords": [
"cors",
"cross-domain",
"http-proxy",
"proxy",
"heroku"
"cors",
"cross-domain",
"http-proxy",
"proxy",
"heroku"
],
"main": "./lib/cors-anywhere.js",
"dependencies": {
@@ -26,11 +26,13 @@
"requires-port": "1.0.0"
},
"devDependencies": {
"eslint": "^2.2.0",
"mocha": "~2.2.4",
"nock": "~1.9.0",
"supertest": "~0.15.0"
},
"scripts": {
"lint": "eslint .",
"test": "./node_modules/.bin/mocha ./test/test*.js --reporter spec"
},
"engines": {
@@ -10,21 +10,21 @@ var originBlacklist = (process.env.CORSANYWHERE_BLACKLIST || '').split(',');
var cors_proxy = require('./lib/cors-anywhere');
cors_proxy.createServer({
originBlacklist: originBlacklist,
requireHeader: ['origin', 'x-requested-with'],
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: {
// Do not add X-Forwarded-For, etc. headers, because Heroku already adds it.
xfwd: false
}
originBlacklist: originBlacklist,
requireHeader: ['origin', 'x-requested-with'],
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: {
// Do not add X-Forwarded-For, etc. headers, because Heroku already adds it.
xfwd: false,
},
}).listen(port, host, function() {
console.log('Running CORS Anywhere on ' + host + ':' + port);
console.log('Running CORS Anywhere on ' + host + ':' + port);
});
@@ -6,7 +6,7 @@ function echoheaders(origin) {
nock(origin)
.persist()
.get('/echoheaders')
.reply(function(uri) {
.reply(function() {
var headers = this.req.headers;
var excluded_headers = [
'accept-encoding',
@@ -49,18 +49,18 @@ nock('http://example.com')
.get('/redirecttarget')
.reply(200, 'redirect target', {
'Some-header': 'value'
'Some-header': 'value',
})
.head('/redirect')
.reply(302, '', {
'Location': '/redirecttarget'
Location: '/redirecttarget',
})
.get('/redirect')
.reply(302, 'redirecting...', {
'header at redirect': 'should not be here',
'Location': '/redirecttarget'
Location: '/redirecttarget',
})
.get('/redirectposttarget')
@@ -71,22 +71,22 @@ nock('http://example.com')
.post('/redirectpost')
.reply(302, 'redirecting...', {
'Location': '/redirectposttarget'
Location: '/redirectposttarget',
})
.post('/redirect307')
.reply(307, 'redirecting...', {
'Location': '/redirectposttarget'
Location: '/redirectposttarget',
})
.get('/redirect2redirect')
.reply(302, 'redirecting to redirect...', {
'Location': '/redirect'
Location: '/redirect',
})
.get('/redirectloop')
.reply(302, 'redirecting ad infinitum...', {
'Location': '/redirectloop'
Location: '/redirectloop',
})
.get('/proxyerror')
@@ -1,3 +1,4 @@
/* eslint-env mocha */
// Run this specific test using:
// npm test -- -f memory
var http = require('http');
Oops, something went wrong.

0 comments on commit 0872577

Please sign in to comment.