Skip to content
Myr

fix(cors): avoid setting `Access-Control-Allow-Origin` if there is no matching origin (#3510)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Yuki Tanaka · committed by GitHub · parent 3311664 · Browse files · 2 files+39 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+39 added−6 removed

  • tests:+33 added−4 removed
  • other:+6 added−2 removed

2 files+39 added−6 removed

modified:src/middleware/cors/index.test.ts+33 added-4 removed
modified:src/middleware/cors/index.ts+6 added-2 removed
66 unmodified lines
67 }6869 const findAllowOrigin = ((optsOrigin) => {70 if (typeof optsOrigin === 'string') {71 if (optsOrigin === '*') {71 return () => optsOrigin72 return () => optsOrigin73 } else {74 return (origin: string) => (optsOrigin === origin ? origin : null)75 }76 } else if (typeof optsOrigin === 'function') {77 return optsOrigin78 } else {75 return (origin: string) => (optsOrigin.includes(origin) ? origin : optsOrigin[0])79 return (origin: string) => (optsOrigin.includes(origin) ? origin : null)80 }81 })(opts.origin)8283 return async function cors(c, next) {
62 unmodified lines