feat(cors): allow QUERY by default as a first-class method (#5115)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Taku Amano · committed by Yusuke Wada · parent 2159deb · Browse files · 2 files·+18 added−5 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+18 added−5 removed
- tests:+16 added−3 removed
- other:+2 added−2 removed
Provenance
- Commit
75b8a49- Tree
c1a78e7- Author
Taku Amano <taku@taaas.jp>- Committer
Yusuke Wada <yusuke@kamawada.com>- Parent
2159deb
2 files changed+18 added−5 removed
modified:src/middleware/cors/index.test.ts+16 added-3 removed
143 unmodified lines144 expect(res.headers.get('Vary')).toBeNull()145 })146 147 it('Preflight default', async () => {148- const req = new Request('https://localhost/api/abc', { method: 'OPTIONS' })149- req.headers.append('Access-Control-Request-Headers', 'X-PINGOTHER, Content-Type')148+ const req = new Request('https://localhost/api/abc', {149+ method: 'OPTIONS',150+ headers: {151+ 'Access-Control-Request-Method': 'QUERY',152+ 'Access-Control-Request-Headers': 'X-PINGOTHER, Content-Type',153+ },154+ })155 const res = await app.request(req)156 157 expect(res.status).toBe(204)158 expect(res.statusText).toBe('No Content')154- expect(res.headers.get('Access-Control-Allow-Methods')?.split(',')[0]).toBe('GET')159+ expect(res.headers.get('Access-Control-Allow-Methods')?.split(',')).toEqual([160+ 'GET',161+ 'HEAD',162+ 'PUT',163+ 'POST',164+ 'DELETE',165+ 'PATCH',166+ 'QUERY',167+ ])168 expect(res.headers.get('Access-Control-Allow-Headers')?.split(',')).toEqual([169 'X-PINGOTHER',170 'Content-Type',171 ])322 unmodified linesmodified:src/middleware/cors/index.ts+2 added-2 removed
26 unmodified lines2728293031313233343526 unmodified lines6263646566666768697087 unmodified lines26 unmodified lines * @see {@link https://hono.dev/docs/middleware/builtin/cors} * * @param {CORSOptions} [options] - The options for the CORS middleware. * @param {string | string[] | ((origin: string, c: Context) => Promise<string | undefined | null> | string | undefined | null)} [options.origin='*'] - The value of "Access-Control-Allow-Origin" CORS header. * @param {string[] | ((origin: string, c: Context) => Promise<string[]> | string[])} [options.allowMethods=['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH']] - The value of "Access-Control-Allow-Methods" CORS header. * @param {string[] | ((origin: string, c: Context) => Promise<string[]> | string[])} [options.allowMethods=['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH', 'QUERY']] - The value of "Access-Control-Allow-Methods" CORS header. * @param {string[]} [options.allowHeaders=[]] - The value of "Access-Control-Allow-Headers" CORS header. * @param {number} [options.maxAge] - The value of "Access-Control-Max-Age" CORS header. * @param {boolean} [options.credentials] - The value of "Access-Control-Allow-Credentials" CORS header. * @param {string[]} [options.exposeHeaders=[]] - The value of "Access-Control-Expose-Headers" CORS header.26 unmodified lines */export const cors = (options?: CORSOptions): MiddlewareHandler => { const opts = { origin: '*', allowMethods: ['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH'], allowMethods: ['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH', 'QUERY'], allowHeaders: [], exposeHeaders: [], ...options, } satisfies CORSOptions87 unmodified lines