Skip to content

fix: reorder configureMiddleware before Boot so provider routes survive engine rebuild (#975)#1508

Merged
hwbrzzl merged 1 commit into
masterfrom
fix/router-middleware-provider-route-loss
Jun 27, 2026
Merged

fix: reorder configureMiddleware before Boot so provider routes survive engine rebuild (#975)#1508
hwbrzzl merged 1 commit into
masterfrom
fix/router-middleware-provider-route-loss

Conversation

@goravel-coder

Copy link
Copy Markdown
Contributor

Summary

Fixes goravel/goravel#975

Routes registered inside a ServiceProvider.Boot() (e.g. app.MakeRoute().Get(...)) were silently discarded when the application registered any global middleware via WithMiddleware() in bootstrap/app.go. The routes returned 404 at runtime with no error.

Root Cause

In Build(), configureMiddleware() was called after Boot(). When WithMiddleware is used, SetGlobalMiddleware rebuilds the route engine (gin.New() / equivalent). Routes registered by providers during Boot() were on the old engine and lost.

Fix

Reorder configureMiddleware() to run between Register() and Boot() instead of after Boot():

  • Providers register their IoC bindings (including Route facade) → Register()
  • Middleware configured, engine initialized with global middleware → configureMiddleware() (moved here)
  • Providers register routes on the already-configured engine → Boot()
  • App routes via WithRouting also register on the same engine → configureRoutes()

This is a one-line move in foundation/application.go.

…ve engine rebuild (#975)

In Build(), configureMiddleware was called after Boot(), which means routes registered by service providers during Boot() were silently dropped when SetGlobalMiddleware rebuilt the route engine. Moving configureMiddleware between Register() and Boot() ensures the engine is set up with global middleware before providers register their routes.

Fixes goravel/goravel#975
@goravel-coder
goravel-coder requested a review from a team as a code owner June 27, 2026 03:56
@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 69.63%. Comparing base (d174ca3) to head (8c6802e).

Files with missing lines Patch % Lines
foundation/application.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1508   +/-   ##
=======================================
  Coverage   69.63%   69.63%           
=======================================
  Files         384      384           
  Lines       30183    30183           
=======================================
  Hits        21017    21017           
  Misses       8174     8174           
  Partials      992      992           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

hwbrzzl pushed a commit to goravel/example that referenced this pull request Jun 27, 2026
…dleware (#132)

Add a RouteProvider that registers GET /provider-route in its Boot()
method and a test asserting it returns 200. This validates the fix
from goravel/framework#1508 where configureMiddleware was moved
between Register() and Boot() to prevent route loss.

Co-authored-by: opencode <bot@opencode.local>
@hwbrzzl
hwbrzzl merged commit e2e1839 into master Jun 27, 2026
16 of 19 checks passed
@hwbrzzl
hwbrzzl deleted the fix/router-middleware-provider-route-loss branch June 27, 2026 07:42
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.

Routes registered in a ServiceProvider's Boot() are silently dropped when global middleware is set via WithMiddleware()

2 participants