Skip to content

Commit 76ea5be

Browse files
authored
Merge pull request #1459 from MarcelOlsen/fix/aot-strictpath-default
[#1458]: Fix strictPath behaviour when `aot: false` is set
2 parents eb024db + f6aceb1 commit 76ea5be

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ export default class Elysia<
806806
})
807807
}
808808

809-
if (this.config.strictPath === false) {
809+
if (!this.config.strictPath) {
810810
const loosePath = getLoosePath(path)
811811
this.router.dynamic.add(method, loosePath, {
812812
validator,

test/core/aot-strictpath.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { describe, expect, it } from 'bun:test'
2+
import { Elysia } from '../../src'
3+
4+
const req = (path: string) => new Request(`http://localhost${path}`)
5+
6+
describe('AOT and strictPath interaction', () => {
7+
it('should respect default strictPath:false when aot:false', async () => {
8+
const app = new Elysia({
9+
aot: false
10+
})
11+
.get('/ping', () => 'pong')
12+
.group('/api', (app) =>
13+
app.get('/ping', () => 'pong')
14+
)
15+
16+
// All these should return 200 with default strictPath: false
17+
expect(await app.handle(req('/ping')).then((x) => x.status)).toBe(200)
18+
expect(await app.handle(req('/ping/')).then((x) => x.status)).toBe(200)
19+
expect(await app.handle(req('/api/ping')).then((x) => x.status)).toBe(200)
20+
expect(await app.handle(req('/api/ping/')).then((x) => x.status)).toBe(200)
21+
})
22+
23+
it('should respect explicit strictPath:false when aot:false', async () => {
24+
const app = new Elysia({
25+
aot: false,
26+
strictPath: false
27+
})
28+
.get('/ping', () => 'pong')
29+
30+
expect(await app.handle(req('/ping')).then((x) => x.status)).toBe(200)
31+
expect(await app.handle(req('/ping/')).then((x) => x.status)).toBe(200)
32+
})
33+
34+
it('should respect strictPath:true when aot:false', async () => {
35+
const app = new Elysia({
36+
aot: false,
37+
strictPath: true
38+
})
39+
.get('/ping', () => 'pong')
40+
41+
expect(await app.handle(req('/ping')).then((x) => x.status)).toBe(200)
42+
expect(await app.handle(req('/ping/')).then((x) => x.status)).toBe(404)
43+
})
44+
45+
it('should handle group routes with default strictPath when aot:false', async () => {
46+
const app = new Elysia({
47+
aot: false
48+
}).group('/api', (app) =>
49+
app.get('/', () => 'Hello Elysia')
50+
)
51+
52+
// Both /api and /api/ should work with default strictPath
53+
expect(await app.handle(req('/api')).then((x) => x.status)).toBe(200)
54+
expect(await app.handle(req('/api/')).then((x) => x.status)).toBe(200)
55+
})
56+
})

0 commit comments

Comments
 (0)