Skip to content

Commit

Permalink
fix(context): set status correctly (#1814)
Browse files Browse the repository at this point in the history
* fix(context): set `status` correctly

* denoify
  • Loading branch information
yusukebe authored Dec 13, 2023
1 parent a86b75b commit 4c4c4ee
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions deno_dist/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class Context<
this.res = new Response(data, arg)
}

let status = typeof arg === 'number' ? arg : this.#status
const status = typeof arg === 'number' ? arg : arg ? arg.status : this.#status
this.#preparedHeaders ??= {}

this.#headers ??= new Headers()
Expand All @@ -249,7 +249,6 @@ export class Context<
for (const [k, v] of Object.entries(this.#preparedHeaders)) {
this.#headers.set(k, v)
}
status = this.#res.status
}

headers ??= {}
Expand Down
3 changes: 1 addition & 2 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class Context<
this.res = new Response(data, arg)
}

let status = typeof arg === 'number' ? arg : this.#status
const status = typeof arg === 'number' ? arg : arg ? arg.status : this.#status
this.#preparedHeaders ??= {}

this.#headers ??= new Headers()
Expand All @@ -249,7 +249,6 @@ export class Context<
for (const [k, v] of Object.entries(this.#preparedHeaders)) {
this.#headers.set(k, v)
}
status = this.#res.status
}

headers ??= {}
Expand Down
1 change: 1 addition & 0 deletions src/middleware/cors/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('CORS by Middleware', () => {
it('GET default', async () => {
const res = await app.request('http://localhost/api/abc')

expect(res.status).toBe(200)
expect(res.headers.get('Access-Control-Allow-Origin')).toBe('*')
expect(res.headers.get('Vary')).toBeNull()
})
Expand Down

0 comments on commit 4c4c4ee

Please sign in to comment.