Skip to content
Myr

fix(app): set `/` for `path` as default (#1330)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix(app): set `/` for `path` as default * denoify

authored by Yusuke Wada · committed by GitHub · parent 5e653df · Browse files · 5 files+44 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+44 added−6 removed

  • tests:+38 added−0 removed
  • other:+6 added−6 removed

5 files+44 added−6 removed

modified:deno_dist/hono-base.ts+2 added-2 removed
64 unmodified lines
65 To use it, inherit the class and implement router in the constructor.66 */67 router!: Router<H>68 readonly getPath: (request: Request) => string69 private _basePath: string = ''70 private path: string = '*'69 private _basePath: string = '/'70 private path: string = '/'7172 routes: RouterRoute[] = []7374 constructor(init: Partial<Pick<Hono, 'router' | 'getPath'> & { strict: boolean }> = {}) {
315 unmodified lines
modified:deno_dist/types.ts+1 added-1 removed
65 unmodified lines
66export interface HandlerInterface<67 E extends Env = Env,68 M extends string = any,69 S = {},70 BasePath extends string = ''70 BasePath extends string = '/'71> {72 //// app.get(...handlers[])7374 // app.get(handler, handler)
370 unmodified lines
modified:src/hono-base.ts+2 added-2 removed
64 unmodified lines
65 To use it, inherit the class and implement router in the constructor.66 */67 router!: Router<H>68 readonly getPath: (request: Request) => string69 private _basePath: string = ''70 private path: string = '*'69 private _basePath: string = '/'70 private path: string = '/'7172 routes: RouterRoute[] = []7374 constructor(init: Partial<Pick<Hono, 'router' | 'getPath'> & { strict: boolean }> = {}) {
315 unmodified lines
modified:src/hono.test.ts+38 added
1267 unmodified lines
1268 const res = await app.request('http://localhost/foo')1269 expect(res.status).toBe(200)1270 expect(await res.text()).toBe('bar')1271 })12721273 describe('With app.get(...handler)', () => {1274 const app = new Hono()1275 const about = new Hono()1276 about.get((c) => c.text('me'))1277 const subApp = new Hono()1278 subApp.route('/about', about)1279 app.route('/', subApp)12801281 it('Should return 200 response - /about', async () => {1282 const res = await app.request('/about')1283 expect(res.status).toBe(200)1284 expect(await res.text()).toBe('me')1285 })12861287 test('Should return 404 response /about/foo', async () => {1288 const res = await app.request('/about/foo')1289 expect(res.status).toBe(404)1290 })1291 })12921293 describe('With app.get(...handler) and app.basePath()', () => {1294 const app = new Hono()1295 const about = new Hono().basePath('/about')1296 about.get((c) => c.text('me'))1297 app.route('/', about)12981299 it('Should return 200 response - /about', async () => {1300 const res = await app.request('/about')1301 expect(res.status).toBe(200)1302 expect(await res.text()).toBe('me')1303 })13041305 test('Should return 404 response /about/foo', async () => {1306 const res = await app.request('/about/foo')1307 expect(res.status).toBe(404)1308 })1309 })1310 })13111312 describe('Chaining', () => {1313 const app = new Hono()
1018 unmodified lines
modified:src/types.ts+1 added-1 removed
65 unmodified lines
66export interface HandlerInterface<67 E extends Env = Env,68 M extends string = any,69 S = {},70 BasePath extends string = ''70 BasePath extends string = '/'71> {72 //// app.get(...handlers[])7374 // app.get(handler, handler)
370 unmodified lines