Skip to content

Commit f26cd19

Browse files
committed
🔧 fix: empty path on slash
1 parent f054cd0 commit f26cd19

File tree

4 files changed

+45
-72
lines changed

4 files changed

+45
-72
lines changed

example/a.ts

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,10 @@
1-
import { Value } from '@sinclair/typebox/value'
21
import { Elysia, t } from '../src'
32

4-
const sessionName = 'user'
3+
export const app = new Elysia()
4+
.get('', () => 'Level 2')
5+
.get(
6+
'/:id',
7+
({ params: { id } }) => `You are in the identified route! ${id}`
8+
)
59

6-
const app = new Elysia({
7-
cookie: {
8-
path: '/'
9-
}
10-
})
11-
.model({
12-
a: t.String()
13-
})
14-
.guard({
15-
body: 'a',
16-
response: {
17-
401: 'a'
18-
}
19-
})
20-
.get('/a', ({ cookie: { session } }) => {
21-
return (session.value = 'abc')
22-
})
23-
.get('/b', ({ cookie: { session }, set }) => {
24-
const value = session.value
25-
26-
session.remove()
27-
28-
return 'v:' + value
29-
})
30-
.get('/async', async ({ error }) => {
31-
if (Math.random() > 0.5) return error(418)
32-
33-
return 'ok'
34-
})
35-
.listen(3000)
36-
37-
app._routes.async
10+
type Res = typeof app._routes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "elysia",
33
"description": "Ergonomic Framework for Human",
4-
"version": "1.0.0-rc.10",
4+
"version": "1.0.0-rc.11",
55
"author": {
66
"name": "saltyAom",
77
"url": "https://github.com/SaltyAom",

src/index.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,7 +3189,7 @@ export default class Elysia<
31893189
const Handle extends InlineHandler<
31903190
Schema,
31913191
Singleton & EphemeralSingleton,
3192-
`${BasePath}${Path}`
3192+
`${BasePath}${Path extends '/' ? '' : Path}`
31933193
>
31943194
>(
31953195
path: Path,
@@ -3200,7 +3200,7 @@ export default class Elysia<
32003200
Singleton & EphemeralSingleton,
32013201
Definitions['error'],
32023202
Metadata['macro'] & EphemeralMetadata['macro'],
3203-
`${BasePath}${Path}`
3203+
`${BasePath}${Path extends '/' ? '/index' : Path}`
32043204
>
32053205
): Elysia<
32063206
BasePath,
@@ -3210,7 +3210,7 @@ export default class Elysia<
32103210
Metadata,
32113211
Routes &
32123212
CreateEden<
3213-
`${BasePath & string}${Path}`,
3213+
`${BasePath & string}${Path extends '/' ? '/index' : Path}`,
32143214
{
32153215
get: {
32163216
body: Schema['body']
@@ -3262,7 +3262,7 @@ export default class Elysia<
32623262
const Handle extends InlineHandler<
32633263
Schema,
32643264
Singleton & EphemeralSingleton,
3265-
`${BasePath}${Path}`
3265+
`${BasePath}${Path extends '/' ? '/index' : Path}`
32663266
>
32673267
>(
32683268
path: Path,
@@ -3273,7 +3273,7 @@ export default class Elysia<
32733273
Singleton & EphemeralSingleton,
32743274
Definitions['error'],
32753275
Metadata['macro'] & EphemeralMetadata['macro'],
3276-
`${BasePath}${Path}`
3276+
`${BasePath}${Path extends '/' ? '/index' : Path}`
32773277
>
32783278
): Elysia<
32793279
BasePath,
@@ -3283,7 +3283,7 @@ export default class Elysia<
32833283
Metadata,
32843284
Routes &
32853285
CreateEden<
3286-
`${BasePath & string}${Path}`,
3286+
`${BasePath & string}${Path extends '/' ? '/index' : Path}`,
32873287
{
32883288
post: {
32893289
body: Schema['body']
@@ -3335,7 +3335,7 @@ export default class Elysia<
33353335
const Handle extends InlineHandler<
33363336
Schema,
33373337
Singleton & EphemeralSingleton,
3338-
`${BasePath}${Path}`
3338+
`${BasePath}${Path extends '/' ? '/index' : Path}`
33393339
>
33403340
>(
33413341
path: Path,
@@ -3346,7 +3346,7 @@ export default class Elysia<
33463346
Singleton & EphemeralSingleton,
33473347
Definitions['error'],
33483348
Metadata['macro'] & EphemeralMetadata['macro'],
3349-
`${BasePath}${Path}`
3349+
`${BasePath}${Path extends '/' ? '/index' : Path}`
33503350
>
33513351
): Elysia<
33523352
BasePath,
@@ -3356,7 +3356,7 @@ export default class Elysia<
33563356
Metadata,
33573357
Routes &
33583358
CreateEden<
3359-
`${BasePath & string}${Path}`,
3359+
`${BasePath & string}${Path extends '/' ? '/index' : Path}`,
33603360
{
33613361
put: {
33623362
body: Schema['body']
@@ -3408,7 +3408,7 @@ export default class Elysia<
34083408
const Handle extends InlineHandler<
34093409
Schema,
34103410
Singleton & EphemeralSingleton,
3411-
`${BasePath}${Path}`
3411+
`${BasePath}${Path extends '/' ? '/index' : Path}`
34123412
>
34133413
>(
34143414
path: Path,
@@ -3419,7 +3419,7 @@ export default class Elysia<
34193419
Singleton & EphemeralSingleton,
34203420
Definitions['error'],
34213421
Metadata['macro'] & EphemeralMetadata['macro'],
3422-
`${BasePath}${Path}`
3422+
`${BasePath}${Path extends '/' ? '/index' : Path}`
34233423
>
34243424
): Elysia<
34253425
BasePath,
@@ -3429,7 +3429,7 @@ export default class Elysia<
34293429
Metadata,
34303430
Routes &
34313431
CreateEden<
3432-
`${BasePath & string}${Path}`,
3432+
`${BasePath & string}${Path extends '/' ? '/index' : Path}`,
34333433
{
34343434
patch: {
34353435
body: Schema['body']
@@ -3481,7 +3481,7 @@ export default class Elysia<
34813481
const Handle extends InlineHandler<
34823482
Schema,
34833483
Singleton & EphemeralSingleton,
3484-
`${BasePath}${Path}`
3484+
`${BasePath}${Path extends '/' ? '/index' : Path}`
34853485
>
34863486
>(
34873487
path: Path,
@@ -3492,7 +3492,7 @@ export default class Elysia<
34923492
Singleton & EphemeralSingleton,
34933493
Definitions['error'],
34943494
Metadata['macro'] & EphemeralMetadata['macro'],
3495-
`${BasePath}${Path}`
3495+
`${BasePath}${Path extends '/' ? '/index' : Path}`
34963496
>
34973497
): Elysia<
34983498
BasePath,
@@ -3502,7 +3502,7 @@ export default class Elysia<
35023502
Metadata,
35033503
Routes &
35043504
CreateEden<
3505-
`${BasePath & string}${Path}`,
3505+
`${BasePath & string}${Path extends '/' ? '/index' : Path}`,
35063506
{
35073507
delete: {
35083508
body: Schema['body']
@@ -3554,7 +3554,7 @@ export default class Elysia<
35543554
const Handle extends InlineHandler<
35553555
Schema,
35563556
Singleton & EphemeralSingleton,
3557-
`${BasePath}${Path}`
3557+
`${BasePath}${Path extends '/' ? '/index' : Path}`
35583558
>
35593559
>(
35603560
path: Path,
@@ -3565,7 +3565,7 @@ export default class Elysia<
35653565
Singleton & EphemeralSingleton,
35663566
Definitions['error'],
35673567
Metadata['macro'] & EphemeralMetadata['macro'],
3568-
`${BasePath}${Path}`
3568+
`${BasePath}${Path extends '/' ? '/index' : Path}`
35693569
>
35703570
): Elysia<
35713571
BasePath,
@@ -3575,7 +3575,7 @@ export default class Elysia<
35753575
Metadata,
35763576
Routes &
35773577
CreateEden<
3578-
`${BasePath & string}${Path}`,
3578+
`${BasePath & string}${Path extends '/' ? '/index' : Path}`,
35793579
{
35803580
options: {
35813581
body: Schema['body']
@@ -3627,7 +3627,7 @@ export default class Elysia<
36273627
const Handle extends InlineHandler<
36283628
Schema,
36293629
Singleton & EphemeralSingleton,
3630-
`${BasePath}${Path}`
3630+
`${BasePath}${Path extends '/' ? '/index' : Path}`
36313631
>
36323632
>(
36333633
path: Path,
@@ -3638,7 +3638,7 @@ export default class Elysia<
36383638
Singleton & EphemeralSingleton,
36393639
Definitions['error'],
36403640
Metadata['macro'] & EphemeralMetadata['macro'],
3641-
`${BasePath}${Path}`
3641+
`${BasePath}${Path extends '/' ? '/index' : Path}`
36423642
>
36433643
): Elysia<
36443644
BasePath,
@@ -3648,7 +3648,7 @@ export default class Elysia<
36483648
Metadata,
36493649
Routes &
36503650
CreateEden<
3651-
`${BasePath & string}${Path}`,
3651+
`${BasePath & string}${Path extends '/' ? '/index' : Path}`,
36523652
{
36533653
[method in string]: {
36543654
body: Schema['body']
@@ -3700,7 +3700,7 @@ export default class Elysia<
37003700
const Handle extends InlineHandler<
37013701
Schema,
37023702
Singleton & EphemeralSingleton,
3703-
`${BasePath}${Path}`
3703+
`${BasePath}${Path extends '/' ? '/index' : Path}`
37043704
>
37053705
>(
37063706
path: Path,
@@ -3711,7 +3711,7 @@ export default class Elysia<
37113711
Singleton & EphemeralSingleton,
37123712
Definitions['error'],
37133713
Metadata['macro'] & EphemeralMetadata['macro'],
3714-
`${BasePath}${Path}`
3714+
`${BasePath}${Path extends '/' ? '/index' : Path}`
37153715
>
37163716
): Elysia<
37173717
BasePath,
@@ -3721,7 +3721,7 @@ export default class Elysia<
37213721
Metadata,
37223722
Routes &
37233723
CreateEden<
3724-
`${BasePath & string}${Path}`,
3724+
`${BasePath & string}${Path extends '/' ? '/index' : Path}`,
37253725
{
37263726
head: {
37273727
body: Schema['body']
@@ -3773,7 +3773,7 @@ export default class Elysia<
37733773
const Handle extends InlineHandler<
37743774
Schema,
37753775
Singleton & EphemeralSingleton,
3776-
`${BasePath}${Path}`
3776+
`${BasePath}${Path extends '/' ? '/index' : Path}`
37773777
>
37783778
>(
37793779
path: Path,
@@ -3784,7 +3784,7 @@ export default class Elysia<
37843784
Singleton & EphemeralSingleton,
37853785
Definitions['error'],
37863786
Metadata['macro'] & EphemeralMetadata['macro'],
3787-
`${BasePath}${Path}`
3787+
`${BasePath}${Path extends '/' ? '/index' : Path}`
37883788
>
37893789
): Elysia<
37903790
BasePath,
@@ -3794,7 +3794,7 @@ export default class Elysia<
37943794
Metadata,
37953795
Routes &
37963796
CreateEden<
3797-
`${BasePath & string}${Path}`,
3797+
`${BasePath & string}${Path extends '/' ? '/index' : Path}`,
37983798
{
37993799
connect: {
38003800
body: Schema['body']
@@ -3847,7 +3847,7 @@ export default class Elysia<
38473847
const Handle extends InlineHandler<
38483848
Schema,
38493849
Singleton & EphemeralSingleton,
3850-
`${BasePath}${Path}`
3850+
`${BasePath}${Path extends '/' ? '/index' : Path}`
38513851
>
38523852
>(
38533853
method: Method,
@@ -3859,7 +3859,7 @@ export default class Elysia<
38593859
Singleton & EphemeralSingleton,
38603860
Definitions['error'],
38613861
Metadata['macro'] & EphemeralMetadata['macro'],
3862-
`${BasePath}${Path}`
3862+
`${BasePath}${Path extends '/' ? '/index' : Path}`
38633863
> & {
38643864
config: {
38653865
allowMeta?: boolean
@@ -3873,7 +3873,7 @@ export default class Elysia<
38733873
Metadata,
38743874
Routes &
38753875
CreateEden<
3876-
`${BasePath & string}${Path}`,
3876+
`${BasePath & string}${Path extends '/' ? '/index' : Path}`,
38773877
{
38783878
[method in Method]: {
38793879
body: Schema['body']
@@ -3931,7 +3931,7 @@ export default class Elysia<
39313931
Singleton & EphemeralSingleton,
39323932
Definitions['error'],
39333933
Metadata['macro'] & EphemeralMetadata['macro'],
3934-
`${BasePath}${Path}`
3934+
`${BasePath}${Path extends '/' ? '/index' : Path}`
39353935
>
39363936
): Elysia<
39373937
BasePath,
@@ -3941,7 +3941,7 @@ export default class Elysia<
39413941
Metadata,
39423942
Routes &
39433943
CreateEden<
3944-
`${BasePath}${Path}`,
3944+
`${BasePath}${Path extends '/' ? '/index' : Path}`,
39453945
{
39463946
subscribe: {
39473947
body: Schema['body']

test/types/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ app.use(plugin).group(
510510
.get('/', () => 1)
511511

512512
type App = (typeof server)['_routes']
513-
type Route = App['']['get']
513+
type Route = App['index']['get']
514514

515515
expectTypeOf<Route>().toEqualTypeOf<{
516516
body: unknown
@@ -570,7 +570,7 @@ app.use(plugin).group(
570570
const server = app.get('/', () => 'Hello').get('/a', () => 'hi')
571571

572572
type App = (typeof server)['_routes']
573-
type Route = App['']['get']
573+
type Route = App['index']['get']
574574

575575
expectTypeOf<Route>().toEqualTypeOf<{
576576
body: unknown
@@ -775,7 +775,7 @@ app.group(
775775
const server = app.use(plugin)
776776

777777
type App = (typeof server)['_routes']
778-
type Route = App['']['get']
778+
type Route = App['index']['get']
779779

780780
expectTypeOf<Route>().toEqualTypeOf<{
781781
body: unknown
@@ -812,12 +812,12 @@ app.group(
812812
const plugin = new Elysia({
813813
prefix: '/v1',
814814
scoped: false
815-
}).get('/', () => 'hello')
815+
}).get('', () => 'hello')
816816

817817
const server = app.use(plugin)
818818

819819
type App = (typeof server)['_routes']
820-
type Route = App['v1']['']['get']
820+
type Route = App['v1']['get']
821821

822822
expectTypeOf<Route>().toEqualTypeOf<{
823823
body: unknown

0 commit comments

Comments
 (0)