Skip to content

Commit 7358ab3

Browse files
CleberRossifengmk2
authored andcommitted
fix: Calling all options even if origin header is not present (#87)
As Origin header is not set in all fetch. I understand that we need to be able to validade, even if the origin is not present. We are still following https://fetch.spec.whatwg.org/#http-origin but grating headers to be added to response on user needs Fix #18
1 parent b49b085 commit 7358ab3

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ module.exports = function(options) {
5858
// https://github.com/rs/cors/issues/10
5959
ctx.vary('Origin');
6060

61-
if (!requestOrigin) return await next();
62-
6361
let origin;
6462
if (typeof options.origin === 'function') {
6563
origin = await options.origin(ctx);

test/cors.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ describe('cors.test.js', function() {
7777
.expect({ foo: 'bar' })
7878
.expect(200, done);
7979
});
80+
81+
it('should always set `Access-Control-Allow-Origin` to *, even if no Origin is passed on request', function(done) {
82+
request(app.listen())
83+
.get('/')
84+
.expect('Access-Control-Allow-Origin', '*')
85+
.expect({ foo: 'bar' })
86+
.expect(200, done);
87+
});
8088
});
8189

8290
describe('options.secureContext=true', function() {

0 commit comments

Comments
 (0)