Skip to content

Conversation

MarcelOlsen
Copy link

@MarcelOlsen MarcelOlsen commented Oct 5, 2025

Description

Fixes strictPath default behavior when aot: false is set. This solves #1458

The Bug

When you set aot: false without explicitly specifying strictPath,
routes behave as if strictPath: true is enabled. This causes paths with
trailing slashes to return 404.

Example:

const app = new Elysia({ aot: false })
  .get("/ping", () => "pong")
  .group("/api", (app) => app.get("/ping", () => "pong"))

Returns 404, should be 200

await app.handle(req("/ping/"))
await app.handle(req("/api/ping/"))

Root Cause

Line 812 in src/index.ts uses strict equality:

if (this.config.strictPath === false) {

When strictPath is undefined (the default), undefined === false evaluates
to false, so loose path variants never get added to the dynamic router.

The Fix

Changed to truthy check:

if (!this.config.strictPath) {

This matches the pattern used elsewhere in the codebase (lines 1024, 1042,
1048, and compose.ts:2271).

Tests

Added test/core/aot-strictpath.test.ts covering:

  • Default strictPath behavior with aot:false
  • Explicit strictPath:false with aot:false
  • strictPath:true with aot:false
  • Group routes with default strictPath

Summary by CodeRabbit

  • New Features
    • More permissive routing in non-strict mode: paths with or without trailing slashes are accepted when strict path handling is disabled or unset.
  • Bug Fixes
    • Improved consistency of route matching for trailing slashes when strict path handling isn’t explicitly enabled.
  • Tests
    • Added comprehensive tests covering strict vs. non-strict path behavior, including default settings, explicit true/false, AOT mode interactions, and grouped routes.

Copy link

coderabbitai bot commented Oct 5, 2025

Walkthrough

The strictPath guard in src/index.ts was broadened from equality false to a general falsy check, affecting when loose and encoded loose paths are registered. A new test file was added to validate strictPath behavior across AOT and grouped routes.

Changes

Cohort / File(s) Summary
Router strictPath condition
src/index.ts
Replaced this.config.strictPath === false with !this.config.strictPath, enabling non-strict path handling for any falsy value (false, undefined, null).
AOT + strictPath tests
test/core/aot-strictpath.test.ts
Added tests covering responses for combinations of AOT mode, strictPath settings (default, false, true), and grouped /api routes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant Router
  participant Handler

  Client->>Router: HTTP request (path)
  alt strictPath is truthy
    Router->>Router: Match exact path only
  else strictPath is falsy (false/undefined/null)
    Router->>Router: Register/match loose and encoded loose variants
  end
  Router->>Handler: Invoke matched route
  Handler-->>Client: Response (200 or 404)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A bunny taps routes in tidy rows,
Loosened paths where the request flows.
If strict is off, the slashes sing—
/ping or /ping/, both happily ring.
With AOT watching, tests align,
The burrow’s routes now match just fine. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title directly references the core fix of the pull request by highlighting the adjustment of the strictPath default in AOT mode, which aligns with the main change described in the diff and PR objectives.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 668c7a1 and f6aceb1.

📒 Files selected for processing (2)
  • src/index.ts (1 hunks)
  • test/core/aot-strictpath.test.ts (1 hunks)
🔇 Additional comments (2)
src/index.ts (1)

812-812: LGTM! Fixes strictPath default behavior in non-AOT mode.

This change correctly broadens the condition from strict equality (=== false) to a falsy check (!), which ensures that when strictPath is undefined (not explicitly set), the loose path variants are registered. This aligns with:

The change treats undefined the same as false, enabling loose path matching (with trailing slashes) by default when aot: false is used.

test/core/aot-strictpath.test.ts (1)

1-56: LGTM! Comprehensive test coverage for the strictPath fix.

The test suite thoroughly validates the interaction between aot: false and strictPath settings:

  1. Default behavior (lines 7-21): Confirms that when strictPath is undefined, both exact paths and paths with trailing slashes work correctly (200 response)
  2. Explicit false (lines 23-32): Validates that explicitly setting strictPath: false works as expected
  3. Explicit true (lines 34-43): Ensures that strictPath: true correctly rejects trailing slashes (404 response)
  4. Group routes (lines 45-55): Verifies the default behavior works correctly with grouped routes

The tests directly validate the fix described in the PR, ensuring that the default strictPath behavior (when undefined) now correctly allows loose path matching when aot: false.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

  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.
@MarcelOlsen MarcelOlsen force-pushed the fix/aot-strictpath-default branch from 6cf3548 to f6aceb1 Compare October 5, 2025 21:10
@MarcelOlsen
Copy link
Author

@coderabbitai review

Copy link

coderabbitai bot commented Oct 5, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@MarcelOlsen MarcelOlsen marked this pull request as ready for review October 5, 2025 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant