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
Provenance
- Commit
acbd495- Tree
e540a32- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
GitHub <noreply@github.com>- Parent
5e653df
5 files changed+44 added−6 removed
modified:deno_dist/hono-base.ts+2 added-2 removed
64 unmodified lines65 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 = '/'71 72 routes: RouterRoute[] = []73 74 constructor(init: Partial<Pick<Hono, 'router' | 'getPath'> & { strict: boolean }> = {}) {315 unmodified linesmodified:deno_dist/types.ts+1 added-1 removed
65 unmodified lines66 export 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[])73 74 // app.get(handler, handler)370 unmodified linesmodified:src/hono-base.ts+2 added-2 removed
64 unmodified lines65 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 = '/'71 72 routes: RouterRoute[] = []73 74 constructor(init: Partial<Pick<Hono, 'router' | 'getPath'> & { strict: boolean }> = {}) {315 unmodified linesmodified:src/hono.test.ts+38 added
1267 unmodified lines1268 const res = await app.request('http://localhost/foo')1269 expect(res.status).toBe(200)1270 expect(await res.text()).toBe('bar')1271 })1272+1273+ 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)1280+1281+ 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+ })1286+1287+ test('Should return 404 response /about/foo', async () => {1288+ const res = await app.request('/about/foo')1289+ expect(res.status).toBe(404)1290+ })1291+ })1292+1293+ 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)1298+1299+ 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+ })1304+1305+ 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 })1311 1312 describe('Chaining', () => {1313 const app = new Hono()1018 unmodified linesmodified:src/types.ts+1 added-1 removed
65 unmodified lines66 export 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[])73 74 // app.get(handler, handler)370 unmodified lines