feat: Enable to add subApp with basePath. (#998)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* feat: Enable to add subApp with basePath. * chore: denoify.
authored by Taku Amano · committed by GitHub · parent e0cead6 · Browse files · 3 files·+19 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+19 added−8 removed
- tests:+11 added−0 removed
- other:+8 added−8 removed
Provenance
- Commit
c0af3d0- Tree
10731fc- Author
Taku Amano <taku@taaas.jp>- Committer
GitHub <noreply@github.com>- Parent
e0cead6
3 files changed+19 added−8 removed
modified:deno_dist/hono.ts+4 added-4 removed
132 unmodified lines133 134 private notFoundHandler: NotFoundHandler = notFoundHandler135 private errorHandler: ErrorHandler = errorHandler136 137- route<SubPath extends string, SubEnv extends Env, SubSchema>(137+ route<SubPath extends string, SubEnv extends Env, SubSchema, SubBasePath extends string>(138 path: SubPath,139- app: Hono<SubEnv, SubSchema>139+ app: Hono<SubEnv, SubSchema, SubBasePath>140 ): Hono<E, RemoveBlankRecord<MergeSchemaPath<SubSchema, SubPath> | S>, BasePath>141 /** @deprecated142 * Use `basePath` instead of `route` with one argument.143 * The `route` with one argument has been removed in v4.144 */145 route<SubPath extends string>(path: SubPath): Hono<E, RemoveBlankRecord<S>, BasePath>146- route<SubPath extends string, SubEnv extends Env, SubSchema>(146+ route<SubPath extends string, SubEnv extends Env, SubSchema, SubBasePath extends string>(147 path: SubPath,148- app?: Hono<SubEnv, SubSchema>148+ app?: Hono<SubEnv, SubSchema, SubBasePath>149 ): Hono<E, RemoveBlankRecord<MergeSchemaPath<SubSchema, SubPath> | S>, BasePath> {150 const subApp = this.basePath(path)151 152 if (!app) {161 unmodified linesmodified:src/hono.test.ts+11 added
212 unmodified lines213 expect(res.status).toBe(200)214 expect(await res.text()).toBe('get /add-path-after-route-call')215 })216 217+ it('Nested route - subApp with basePath', async () => {218+ const app = new Hono()219+ const book = new Hono().basePath('/book')220+ book.get('/', (c) => c.text('get /book'))221+ app.route('/api', book)222+223+ const res = await app.request('http://localhost/api/book', { method: 'GET' })224+ expect(res.status).toBe(200)225+ expect(await res.text()).toBe('get /book')226+ })227+228 it('Multiple route', async () => {229 const app = new Hono()230 231 const book = new Hono()1586 unmodified linesmodified:src/hono.ts+4 added-4 removed
132 unmodified lines133 134 private notFoundHandler: NotFoundHandler = notFoundHandler135 private errorHandler: ErrorHandler = errorHandler136 137- route<SubPath extends string, SubEnv extends Env, SubSchema>(137+ route<SubPath extends string, SubEnv extends Env, SubSchema, SubBasePath extends string>(138 path: SubPath,139- app: Hono<SubEnv, SubSchema>139+ app: Hono<SubEnv, SubSchema, SubBasePath>140 ): Hono<E, RemoveBlankRecord<MergeSchemaPath<SubSchema, SubPath> | S>, BasePath>141 /** @deprecated142 * Use `basePath` instead of `route` with one argument.143 * The `route` with one argument has been removed in v4.144 */145 route<SubPath extends string>(path: SubPath): Hono<E, RemoveBlankRecord<S>, BasePath>146- route<SubPath extends string, SubEnv extends Env, SubSchema>(146+ route<SubPath extends string, SubEnv extends Env, SubSchema, SubBasePath extends string>(147 path: SubPath,148- app?: Hono<SubEnv, SubSchema>148+ app?: Hono<SubEnv, SubSchema, SubBasePath>149 ): Hono<E, RemoveBlankRecord<MergeSchemaPath<SubSchema, SubPath> | S>, BasePath> {150 const subApp = this.basePath(path)151 152 if (!app) {161 unmodified lines