Skip to content

Commit

Permalink
fix(vercel): remove requestContext (honojs#3549)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe authored and TinsFox committed Oct 28, 2024
1 parent 1f45a5d commit 2ad2518
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
29 changes: 10 additions & 19 deletions src/adapter/vercel/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Hono } from '../../hono'
import { handle } from './handler'

describe('Adapter for Next.js', () => {
it('Should return 200 response with a `waitUntil` value', async () => {
it('Should return 200 response', async () => {
const app = new Hono()
app.get('/api/foo', async (c) => {
app.get('/api/author/:name', async (c) => {
const name = c.req.param('name')
return c.json({
path: '/api/foo',
/**
* Checking if the `waitUntil` value is passed.
*/
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
waitUntil: c.executionCtx.waitUntil() as any,
path: '/api/author/:name',
name,
})
})
const handler = handle(app)
const req = new Request('http://localhost/api/foo')
const res = await handler(req, { waitUntil: () => 'waitUntil' } as any)
const req = new Request('http://localhost/api/author/hono')
const res = await handler(req)
expect(res.status).toBe(200)
expect(await res.json()).toEqual({
path: '/api/foo',
waitUntil: 'waitUntil',
path: '/api/author/:name',
name: 'hono',
})
})

Expand All @@ -38,10 +33,6 @@ describe('Adapter for Next.js', () => {

const handler = handle(app)
const req = new Request('http://localhost/api/error')
expect(() =>
handler(req, {
waitUntil: () => {},
} as any)
).toThrowError('Custom Error')
expect(() => handler(req)).toThrowError('Custom Error')
})
})
5 changes: 2 additions & 3 deletions src/adapter/vercel/handler.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { Hono } from '../../hono'
import type { FetchEventLike } from '../../types'

export const handle =
(app: Hono<any, any, any>) =>
(req: Request, requestContext: FetchEventLike): Response | Promise<Response> => {
return app.fetch(req, {}, requestContext as any)
(req: Request): Response | Promise<Response> => {
return app.fetch(req)
}

0 comments on commit 2ad2518

Please sign in to comment.