mirror of
https://github.com/Rob--W/cors-anywhere.git
synced 2026-06-03 14:07:57 -09:00
Enforce a consistent coding style using eslint
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"node": true,
|
||||
"eqnull": true,
|
||||
"undef": true,
|
||||
"unused": "vars",
|
||||
"mocha": true
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -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": {
|
||||
|
||||
@@ -19,12 +19,12 @@ cors_proxy.createServer({
|
||||
'x-heroku-queue-wait-time',
|
||||
'x-heroku-queue-depth',
|
||||
'x-heroku-dynos-in-use',
|
||||
'x-request-start'
|
||||
'x-request-start',
|
||||
],
|
||||
httpProxyOptions: {
|
||||
// Do not add X-Forwarded-For, etc. headers, because Heroku already adds it.
|
||||
xfwd: false
|
||||
}
|
||||
xfwd: false,
|
||||
},
|
||||
}).listen(port, host, function() {
|
||||
console.log('Running CORS Anywhere on ' + host + ':' + port);
|
||||
});
|
||||
|
||||
+8
-8
@@ -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');
|
||||
|
||||
+10
-9
@@ -1,3 +1,4 @@
|
||||
/* eslint-env mocha */
|
||||
require('./setup');
|
||||
|
||||
var createServer = require('../').createServer;
|
||||
@@ -132,7 +133,7 @@ describe('Basic functionality', function() {
|
||||
.post('/example.com/echopost')
|
||||
.attach('file', path.join(__dirname, 'dummy.txt'))
|
||||
.expect('Access-Control-Allow-Origin', '*')
|
||||
.expect(/\r\nContent-Disposition: form-data; name="file"; filename="dummy.txt"\r\nContent-Type: text\/plain\r\n\r\ndummy content\n\r\n/, done);
|
||||
.expect(/\r\nContent-Disposition: form-data; name="file"; filename="dummy.txt"\r\nContent-Type: text\/plain\r\n\r\ndummy content\n\r\n/, done); // eslint-disable-line max-len
|
||||
});
|
||||
|
||||
it('HEAD with redirect should be followed', function(done) {
|
||||
@@ -494,7 +495,7 @@ describe('setHeaders', function() {
|
||||
.expect('Access-Control-Allow-Origin', '*')
|
||||
.expectJSON({
|
||||
host: 'example.com',
|
||||
'x-powered-by': 'CORS Anywhere'
|
||||
'x-powered-by': 'CORS Anywhere',
|
||||
}, done);
|
||||
});
|
||||
|
||||
@@ -505,7 +506,7 @@ describe('setHeaders', function() {
|
||||
.expect('Access-Control-Allow-Origin', '*')
|
||||
.expectJSON({
|
||||
host: 'example.com',
|
||||
'x-powered-by': 'CORS Anywhere'
|
||||
'x-powered-by': 'CORS Anywhere',
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -527,7 +528,7 @@ describe('setHeaders + removeHeaders', function() {
|
||||
.expect('Access-Control-Allow-Origin', '*')
|
||||
.expectJSON({
|
||||
host: 'example.com',
|
||||
'x-powered-by': 'CORS Anywhere'
|
||||
'x-powered-by': 'CORS Anywhere',
|
||||
}, done);
|
||||
});
|
||||
|
||||
@@ -538,7 +539,7 @@ describe('setHeaders + removeHeaders', function() {
|
||||
.expect('Access-Control-Allow-Origin', '*')
|
||||
.expectJSON({
|
||||
host: 'example.com',
|
||||
'x-powered-by': 'CORS Anywhere'
|
||||
'x-powered-by': 'CORS Anywhere',
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -547,8 +548,8 @@ describe('httpProxyOptions.xfwd=false', function() {
|
||||
before(function() {
|
||||
cors_anywhere = createServer({
|
||||
httpProxyOptions: {
|
||||
xfwd: false
|
||||
}
|
||||
xfwd: false,
|
||||
},
|
||||
});
|
||||
cors_anywhere_port = cors_anywhere.listen(0).address().port;
|
||||
});
|
||||
@@ -577,8 +578,8 @@ describe('httpProxyOptions.getProxyForUrl', function() {
|
||||
|
||||
cors_anywhere = createServer({
|
||||
httpProxyOptions: {
|
||||
xfwd: false
|
||||
}
|
||||
xfwd: false,
|
||||
},
|
||||
});
|
||||
cors_anywhere_port = cors_anywhere.listen(0).address().port;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user