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.

@coderabbitai
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.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Title Check ✅ Passed The pull request title "[#1458]: Fix strictPath behaviour when aot: false is set" accurately describes the main change in the changeset. The primary modification replaces a strict equality check with a truthy check in src/index.ts to fix the bug where strictPath defaults to strict mode behavior when aot: false is set without explicitly configuring strictPath. The title is clear, specific, and directly reflects the bug fix being implemented, capturing the core issue and solution in a concise manner. A teammate scanning commit history would immediately understand that this PR addresses strictPath default behavior in the context of AOT mode being disabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@coderabbitai
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
@MarcelOlsen MarcelOlsen changed the title Fix/aot strictpath default [#1458]: Fix strictPath behaviour when aot: false is set Oct 21, 2025
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