Skip to content

Commit

Permalink
fix: Calling all options even if origin header is not present (#87)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
CleberRossi authored Oct 5, 2022
1 parent ea0ca7b commit 2e8da5b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ module.exports = function(options) {
// https://github.com/rs/cors/issues/10
ctx.vary('Origin');

if (!requestOrigin) return await next();

let origin;
if (typeof options.origin === 'function') {
origin = await options.origin(ctx);
Expand Down
8 changes: 8 additions & 0 deletions test/cors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ describe('cors.test.js', function() {
.expect({ foo: 'bar' })
.expect(200, done);
});

it('should always set `Access-Control-Allow-Origin` to *, even if no Origin is passed on request', function(done) {
request(app.listen())
.get('/')
.expect('Access-Control-Allow-Origin', '*')
.expect({ foo: 'bar' })
.expect(200, done);
});
});

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

0 comments on commit 2e8da5b

Please # to comment.