Skip to content

Commit 2e8da5b

Browse files
authoredOct 5, 2022
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 ea0ca7b commit 2e8da5b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed
 

‎index.js

-2
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

+8
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)
Please sign in to comment.