Skip to content

Commit

Permalink
feat: use @koa/[email protected] (#27)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: drop Node.js < 14
  • Loading branch information
fengmk2 authored Dec 11, 2023
1 parent 1396d6d commit 599e918
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 15 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
"cors"
],
"dependencies": {
"@koa/cors": "^3.3.0"
"@koa/cors": "^5.0.0"
},
"devDependencies": {
"egg": "^3.17.5",
"egg-bin": "^6.5.2",
"egg-mock": "^5.10.9",
"egg-security": "^3.1.0",
"eslint": "^8.55.0",
"eslint-config-egg": "^12.3.1",
"eslint-config-egg": "12",
"git-contributor": "^2.1.5"
},
"engines": {
"node": ">=8.0.0"
"node": ">=14.0.0"
},
"scripts": {
"contributor": "git-contributor",
Expand Down
4 changes: 2 additions & 2 deletions test/cors.default-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('test/cors.default-config.test.js', () => {
.get('/')
.expect({ foo: 'bar' })
.expect(res => {
assert(!res.headers['access-control-allow-origin']);
assert.equal(res.headers['access-control-allow-origin'], undefined);
})
.expect(200);
});
Expand All @@ -31,7 +31,7 @@ describe('test/cors.default-config.test.js', () => {
.expect('Access-Control-Allow-Credentials', 'true')
.expect({ foo: 'bar' })
.expect(res => {
assert(!res.headers['access-control-allow-origin']);
assert.equal(res.headers['access-control-allow-origin'], undefined);
})
.expect(200);
});
Expand Down
4 changes: 1 addition & 3 deletions test/cors.origin-function.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const assert = require('assert');
const mm = require('egg-mock');

Expand All @@ -21,7 +19,7 @@ describe('test/cors.origin-function.test.js', () => {
.get('/')
.expect({ foo: 'bar' })
.expect(res => {
assert(!res.headers['access-control-allow-origin']);
assert.equal(res.headers['access-control-allow-origin'], undefined);
})
.expect(200);
});
Expand Down
4 changes: 2 additions & 2 deletions test/cors.origin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ describe('test/cors.origin.test.js', () => {

afterEach(mm.restore);

it('should not set `Access-Control-Allow-Origin` when request Origin header missing', () => {
it('should alway set `Access-Control-Allow-Origin` to config.origin=string when request Origin header missing', () => {
return app.httpRequest()
.get('/')
.expect({ foo: 'bar' })
.expect(res => {
assert(!res.headers['access-control-allow-origin']);
assert.equal(res.headers['access-control-allow-origin'], 'eggjs.org');
})
.expect(200);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use strict';

exports.keys = 'foo';

exports.cors = {
async origin() {
async origin(ctx) {
if (!ctx.get('origin')) return '';
return 'eggjs.org';
},
credentials: true,
Expand Down
2 changes: 0 additions & 2 deletions test/fixtures/apps/cors.origin/config/config.default.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

exports.keys = 'foo';

exports.cors = {
Expand Down

0 comments on commit 599e918

Please sign in to comment.