Skip to content

Commit

Permalink
feat: refactor with typescript
Browse files Browse the repository at this point in the history
BREAKING CHANGE: drop Node.js < 16

deps: use @koa/[email protected]

eggjs/egg#5257
  • Loading branch information
fengmk2 committed Dec 11, 2023
1 parent 1396d6d commit 14172fa
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"cors"
],
"dependencies": {
"@koa/cors": "^3.3.0"
"@koa/cors": "^5.0.0"
},
"devDependencies": {
"egg": "^3.17.5",
Expand All @@ -34,7 +34,7 @@
"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 14172fa

Please sign in to comment.