Skip to content

Commit

Permalink
chore: use eslint instead of jshint (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Apr 26, 2016
1 parent bc75122 commit 8dff9b2
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 197 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
@@ -0,0 +1,3 @@
{
"extends": "eslint-config-egg"
}
4 changes: 0 additions & 4 deletions .jshintignore

This file was deleted.

95 changes: 0 additions & 95 deletions .jshintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -5,4 +5,4 @@ node_js:
- '5'
script: 'npm run ci'
after_script:
- 'npm i codecov && ./node_modules/.bin/codecov'
- 'npm i codecov && codecov'
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
This software is licensed under the MIT License.

Copyright (c) 2015 koajs and other contributors
Copyright (c) 2015 - 2016 koajs and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
25 changes: 12 additions & 13 deletions index.js
@@ -1,6 +1,4 @@
/**!
* kcors - index.js
*
/**
* Copyright(c) koajs and other contributors.
* MIT Licensed
*
Expand All @@ -10,7 +8,7 @@

'use strict';

var copy = require('copy-to');
const copy = require('copy-to');

/**
* CORS middleware
Expand All @@ -22,12 +20,12 @@ var copy = require('copy-to');
* - {String|Array} allowHeaders `Access-Control-Allow-Headers`
* - {String|Number} maxAge `Access-Control-Max-Age` in seconds
* - {Boolean} credentials `Access-Control-Allow-Credentials`
* @return {Function}
* @return {Function} cors middleware
* @api public
*/
module.exports = function (options) {
var defaults = {
allowMethods: 'GET,HEAD,PUT,POST,DELETE'
module.exports = function(options) {
const defaults = {
allowMethods: 'GET,HEAD,PUT,POST,DELETE',
};

options = options || {};
Expand All @@ -52,14 +50,16 @@ module.exports = function (options) {
options.credentials = !!options.credentials;

return function cors(ctx, next) {
// If the Origin header is not present terminate this set of steps. The request is outside the scope of this specification.
var requestOrigin = ctx.get('Origin');
// If the Origin header is not present terminate this set of steps.
// The request is outside the scope of this specification.
const requestOrigin = ctx.get('Origin');
if (!requestOrigin) {
return next();
}

var origin;
let origin;
if (typeof options.origin === 'function') {
// FIXME: origin can be promise
origin = options.origin(ctx);
if (!origin) {
return next();
Expand All @@ -70,7 +70,6 @@ module.exports = function (options) {

if (ctx.method !== 'OPTIONS') {
// Simple Cross-Origin Request, Actual Request, and Redirects

ctx.set('Access-Control-Allow-Origin', origin);

if (options.credentials === true) {
Expand Down Expand Up @@ -107,7 +106,7 @@ module.exports = function (options) {
ctx.set('Access-Control-Allow-Methods', options.allowMethods);
}

var allowHeaders = options.allowHeaders;
let allowHeaders = options.allowHeaders;
if (!allowHeaders) {
allowHeaders = ctx.get('Access-Control-Request-Headers');
}
Expand Down
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -10,7 +10,7 @@
"test": "mocha --check-leaks -R spec -t 5000 test/*.test.js",
"test-cov": "istanbul cover _mocha -- --check-leaks -t 5000 test/*.test.js",
"ci": "npm run lint && npm run test-cov",
"lint": "jshint .",
"lint": "eslint index.js test",
"autod": "autod -w --prefix '~'",
"contributors": "contributors -f plain -o AUTHORS"
},
Expand All @@ -21,10 +21,11 @@
"autod": "*",
"contributors": "*",
"istanbul": "*",
"jshint": "*",
"koa": "next",
"mocha": "*",
"supertest": "1"
"supertest": "1",
"eslint-config-egg": "^2.0.0",
"eslint": "^2.3.0"
},
"homepage": "https://github.com/koajs/cors",
"repository": {
Expand Down

0 comments on commit 8dff9b2

Please sign in to comment.