Skip to content
Myr

fix(cors): fix bugs handling pre-flight (#792)

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

authored by Yusuke Wada · committed by GitHub · parent 897c401 · Browse files · 4 files+9 added−13 removed
This commit

State

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

Diff stats

4 files+9 added−13 removed

  • tests:+4 added−4 removed
  • other:+5 added−9 removed

4 files+9 added−13 removed

modified:deno_dist/middleware/cors/index.ts+2 added-4 removed
modified:deno_dist/utils/encode.ts+1 added-1 removed
modified:src/middleware/cors/index.test.ts+4 added-4 removed
29 unmodified lines
30 origin: (origin) => (origin.endsWith('.example.com') ? origin : 'http://example.com'),31 })32 )3334 app.all('/api/abc', (c) => {34 app.get('/api/abc', (c) => {35 return c.json({ success: true })36 })37 app.all('/api2/abc', (c) => {37 app.get('/api2/abc', (c) => {38 return c.json({ success: true })39 })40 app.all('/api3/abc', (c) => {40 app.get('/api3/abc', (c) => {41 return c.json({ success: true })42 })43 app.all('/api4/abc', (c) => {43 app.get('/api4/abc', (c) => {44 return c.json({ success: true })45 })4647 it('GET default', async () => {
86 unmodified lines
modified:src/middleware/cors/index.ts+2 added-4 removed
30 unmodified lines
31 }32 })(opts.origin)3334 return async (c, next) => {35 35 function set(key: string, value: string) {36 c.res.headers.append(key, value)37 }38
17 unmodified lines
56 }5758 if (c.req.method !== 'OPTIONS') {59 await next()61 }62 else {60 } else {61 // Preflight6263 if (opts.maxAge != null) {64 set('Access-Control-Max-Age', opts.maxAge.toString())
17 unmodified lines
8283 c.res.headers.delete('Content-Length')84 c.res.headers.delete('Content-Type')8588 c.res = new Response(null, {86 return new Response(null, {87 headers: c.res.headers,88 status: 204,89 statusText: c.res.statusText,90 })
3 unmodified lines