mirror of
https://github.com/honojs/hono.git
synced 2024-11-30 01:56:18 +01:00
fix(app): set /
for path
as default (#1330)
* fix(app): set `/` for `path` as default * denoify
This commit is contained in:
parent
5e653dfafd
commit
acbd495bbe
@ -66,8 +66,8 @@ class Hono<E extends Env = Env, S = {}, BasePath extends string = '/'> extends d
|
||||
*/
|
||||
router!: Router<H>
|
||||
readonly getPath: (request: Request) => string
|
||||
private _basePath: string = ''
|
||||
private path: string = '*'
|
||||
private _basePath: string = '/'
|
||||
private path: string = '/'
|
||||
|
||||
routes: RouterRoute[] = []
|
||||
|
||||
|
@ -67,7 +67,7 @@ export interface HandlerInterface<
|
||||
E extends Env = Env,
|
||||
M extends string = any,
|
||||
S = {},
|
||||
BasePath extends string = ''
|
||||
BasePath extends string = '/'
|
||||
> {
|
||||
//// app.get(...handlers[])
|
||||
|
||||
|
@ -66,8 +66,8 @@ class Hono<E extends Env = Env, S = {}, BasePath extends string = '/'> extends d
|
||||
*/
|
||||
router!: Router<H>
|
||||
readonly getPath: (request: Request) => string
|
||||
private _basePath: string = ''
|
||||
private path: string = '*'
|
||||
private _basePath: string = '/'
|
||||
private path: string = '/'
|
||||
|
||||
routes: RouterRoute[] = []
|
||||
|
||||
|
@ -1269,6 +1269,44 @@ describe('Hono with `app.route`', () => {
|
||||
expect(res.status).toBe(200)
|
||||
expect(await res.text()).toBe('bar')
|
||||
})
|
||||
|
||||
describe('With app.get(...handler)', () => {
|
||||
const app = new Hono()
|
||||
const about = new Hono()
|
||||
about.get((c) => c.text('me'))
|
||||
const subApp = new Hono()
|
||||
subApp.route('/about', about)
|
||||
app.route('/', subApp)
|
||||
|
||||
it('Should return 200 response - /about', async () => {
|
||||
const res = await app.request('/about')
|
||||
expect(res.status).toBe(200)
|
||||
expect(await res.text()).toBe('me')
|
||||
})
|
||||
|
||||
test('Should return 404 response /about/foo', async () => {
|
||||
const res = await app.request('/about/foo')
|
||||
expect(res.status).toBe(404)
|
||||
})
|
||||
})
|
||||
|
||||
describe('With app.get(...handler) and app.basePath()', () => {
|
||||
const app = new Hono()
|
||||
const about = new Hono().basePath('/about')
|
||||
about.get((c) => c.text('me'))
|
||||
app.route('/', about)
|
||||
|
||||
it('Should return 200 response - /about', async () => {
|
||||
const res = await app.request('/about')
|
||||
expect(res.status).toBe(200)
|
||||
expect(await res.text()).toBe('me')
|
||||
})
|
||||
|
||||
test('Should return 404 response /about/foo', async () => {
|
||||
const res = await app.request('/about/foo')
|
||||
expect(res.status).toBe(404)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Chaining', () => {
|
||||
|
@ -67,7 +67,7 @@ export interface HandlerInterface<
|
||||
E extends Env = Env,
|
||||
M extends string = any,
|
||||
S = {},
|
||||
BasePath extends string = ''
|
||||
BasePath extends string = '/'
|
||||
> {
|
||||
//// app.get(...handlers[])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user