From f6aceb167699d19ad4ac8c3502a60cb10d67e3d5 Mon Sep 17 00:00:00 2001 From: MarcelOlsen Date: Sun, 5 Oct 2025 22:49:16 +0200 Subject: [PATCH] :wrench: fix: strictPath default behavior with aot:false Changed strictPath check from ===false to !this.config.strictPath to properly handle undefined default, fixing trailing slash 404s when aot:false is set without explicit strictPath config. --- src/index.ts | 2 +- test/core/aot-strictpath.test.ts | 56 ++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 test/core/aot-strictpath.test.ts diff --git a/src/index.ts b/src/index.ts index 6239e8cd..0541505a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -809,7 +809,7 @@ export default class Elysia< }) } - if (this.config.strictPath === false) { + if (!this.config.strictPath) { const loosePath = getLoosePath(path) this.router.dynamic.add(method, loosePath, { validator, diff --git a/test/core/aot-strictpath.test.ts b/test/core/aot-strictpath.test.ts new file mode 100644 index 00000000..cfa94acf --- /dev/null +++ b/test/core/aot-strictpath.test.ts @@ -0,0 +1,56 @@ +import { describe, expect, it } from 'bun:test' +import { Elysia } from '../../src' + +const req = (path: string) => new Request(`http://localhost${path}`) + +describe('AOT and strictPath interaction', () => { + it('should respect default strictPath:false when aot:false', async () => { + const app = new Elysia({ + aot: false + }) + .get('/ping', () => 'pong') + .group('/api', (app) => + app.get('/ping', () => 'pong') + ) + + // All these should return 200 with default strictPath: false + expect(await app.handle(req('/ping')).then((x) => x.status)).toBe(200) + expect(await app.handle(req('/ping/')).then((x) => x.status)).toBe(200) + expect(await app.handle(req('/api/ping')).then((x) => x.status)).toBe(200) + expect(await app.handle(req('/api/ping/')).then((x) => x.status)).toBe(200) + }) + + it('should respect explicit strictPath:false when aot:false', async () => { + const app = new Elysia({ + aot: false, + strictPath: false + }) + .get('/ping', () => 'pong') + + expect(await app.handle(req('/ping')).then((x) => x.status)).toBe(200) + expect(await app.handle(req('/ping/')).then((x) => x.status)).toBe(200) + }) + + it('should respect strictPath:true when aot:false', async () => { + const app = new Elysia({ + aot: false, + strictPath: true + }) + .get('/ping', () => 'pong') + + expect(await app.handle(req('/ping')).then((x) => x.status)).toBe(200) + expect(await app.handle(req('/ping/')).then((x) => x.status)).toBe(404) + }) + + it('should handle group routes with default strictPath when aot:false', async () => { + const app = new Elysia({ + aot: false + }).group('/api', (app) => + app.get('/', () => 'Hello Elysia') + ) + + // Both /api and /api/ should work with default strictPath + expect(await app.handle(req('/api')).then((x) => x.status)).toBe(200) + expect(await app.handle(req('/api/')).then((x) => x.status)).toBe(200) + }) +})