Skip to content

Commit 7cdfb57

Browse files
committed
replace eager to alwaysRedirect
1 parent 1b4d0b8 commit 7cdfb57

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/middleware/trailing-slash/index.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ describe('Resolve trailing slash', () => {
8787
})
8888
})
8989

90-
describe('trimTrailingSlash middleware with eager option', () => {
90+
describe('trimTrailingSlash middleware with alwaysRedirect option', () => {
9191
const app = new Hono()
92-
app.use('*', trimTrailingSlash({ eager: true }))
92+
app.use('*', trimTrailingSlash({ alwaysRedirect: true }))
9393

9494
app.get('/', async (c) => {
9595
return c.text('ok')
@@ -255,9 +255,9 @@ describe('Resolve trailing slash', () => {
255255
})
256256
})
257257

258-
describe('appendTrailingSlash middleware with eager option', () => {
258+
describe('appendTrailingSlash middleware with alwaysRedirect option', () => {
259259
const app = new Hono()
260-
app.use('*', appendTrailingSlash({ eager: true }))
260+
app.use('*', appendTrailingSlash({ alwaysRedirect: true }))
261261

262262
app.get('/', async (c) => {
263263
return c.text('ok')

src/middleware/trailing-slash/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type TrimTrailingSlashOptions = {
1313
* If `false` (default), it will only redirect when the route is not found (404).
1414
* @default false
1515
*/
16-
eager?: boolean
16+
alwaysRedirect?: boolean
1717
}
1818

1919
/**
@@ -34,16 +34,16 @@ type TrimTrailingSlashOptions = {
3434
*
3535
* @example
3636
* ```ts
37-
* // With eager option for wildcard routes
37+
* // With alwaysRedirect option for wildcard routes
3838
* const app = new Hono()
3939
*
40-
* app.use(trimTrailingSlash({ eager: true }))
40+
* app.use(trimTrailingSlash({ alwaysRedirect: true }))
4141
* app.get('/my-path/*', (c) => c.text('Wildcard route'))
4242
* ```
4343
*/
4444
export const trimTrailingSlash = (options?: TrimTrailingSlashOptions): MiddlewareHandler => {
4545
return async function trimTrailingSlash(c, next) {
46-
if (options?.eager) {
46+
if (options?.alwaysRedirect) {
4747
if (
4848
(c.req.method === 'GET' || c.req.method === 'HEAD') &&
4949
c.req.path !== '/' &&
@@ -59,7 +59,7 @@ export const trimTrailingSlash = (options?: TrimTrailingSlashOptions): Middlewar
5959
await next()
6060

6161
if (
62-
!options?.eager &&
62+
!options?.alwaysRedirect &&
6363
c.res.status === 404 &&
6464
(c.req.method === 'GET' || c.req.method === 'HEAD') &&
6565
c.req.path !== '/' &&
@@ -81,7 +81,7 @@ type AppendTrailingSlashOptions = {
8181
* If `false` (default), it will only redirect when the route is not found (404).
8282
* @default false
8383
*/
84-
eager?: boolean
84+
alwaysRedirect?: boolean
8585
}
8686

8787
/**
@@ -102,16 +102,16 @@ type AppendTrailingSlashOptions = {
102102
*
103103
* @example
104104
* ```ts
105-
* // With eager option for wildcard routes
105+
* // With alwaysRedirect option for wildcard routes
106106
* const app = new Hono()
107107
*
108-
* app.use(appendTrailingSlash({ eager: true }))
108+
* app.use(appendTrailingSlash({ alwaysRedirect: true }))
109109
* app.get('/my-path/*', (c) => c.text('Wildcard route'))
110110
* ```
111111
*/
112112
export const appendTrailingSlash = (options?: AppendTrailingSlashOptions): MiddlewareHandler => {
113113
return async function appendTrailingSlash(c, next) {
114-
if (options?.eager) {
114+
if (options?.alwaysRedirect) {
115115
if ((c.req.method === 'GET' || c.req.method === 'HEAD') && c.req.path.at(-1) !== '/') {
116116
const url = new URL(c.req.url)
117117
url.pathname += '/'
@@ -123,7 +123,7 @@ export const appendTrailingSlash = (options?: AppendTrailingSlashOptions): Middl
123123
await next()
124124

125125
if (
126-
!options?.eager &&
126+
!options?.alwaysRedirect &&
127127
c.res.status === 404 &&
128128
(c.req.method === 'GET' || c.req.method === 'HEAD') &&
129129
c.req.path.at(-1) !== '/'

0 commit comments

Comments
 (0)