Skip to content

Commit

Permalink
fix(wobe): end request after redirect (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
coratgerl authored Jul 24, 2024
1 parent 777639a commit 3ee5879
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/wobe/src/Context.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it, mock } from 'bun:test'
import { describe, expect, it, mock, spyOn } from 'bun:test'
import { Context } from './Context'

describe('Context', () => {
Expand Down Expand Up @@ -58,13 +58,18 @@ describe('Context', () => {
const request = new Request('https://example.com')
const context = new Context(request)

const spyContextRes = spyOn(context.res, 'send')

context.redirect('https://example.com/test')

expect(context.res.headers.get('Location')).toEqual(
'https://example.com/test',
)
expect(context.res.status).toEqual(302)

expect(spyContextRes).toHaveBeenCalledTimes(1)
expect(spyContextRes).toHaveBeenCalledWith('OK')

// Redirect permanently
context.redirect('https://example.com/test2', 301)

Expand Down
2 changes: 2 additions & 0 deletions packages/wobe/src/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export class Context {
redirect(url: string, status = 302) {
this.res.headers.set('Location', url)
this.res.status = status

this.res.send('OK')
}

/**
Expand Down

0 comments on commit 3ee5879

Please sign in to comment.