Skip to content

Commit 2ace18c

Browse files
authored
Merge pull request #1066 from workarea-commerce/issue-1058-enforce-host-middleware
fix: Rails 7.0 EnforceHostMiddleware NameError (WA-VERIFY-071 follow-up)
2 parents 3ef8c87 + 343f541 commit 2ace18c

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

core/config/initializers/10_rack_middleware.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,30 @@
5353
"#{Workarea::Admin.root}/public"
5454
)
5555

56+
# Rails 7.0 uses Zeitwerk autoloading, but initializers run before Zeitwerk
57+
# has eager-loaded app/middleware constants. Require these middleware files
58+
# explicitly to guarantee the constants are defined when the middleware stack
59+
# is configured.
60+
#
61+
# On Rails 6.x these requires are no-ops (the constants are already loaded or
62+
# will be auto-required); on Rails 7.1+ this pattern remains safe.
63+
#
64+
# Decision rationale: Rails 7.0 introduced native `config.hosts` enforcement
65+
# which covers host header validation at the ActionDispatch level. However,
66+
# Workarea's EnforceHostMiddleware provides Workarea-specific redirect behavior
67+
# (respecting Workarea.config.enforce_host / config.host / skip_enforce_host)
68+
# that `config.hosts` does not replicate. We therefore keep the middleware and
69+
# fix the autoload gap instead of removing it.
70+
require_relative '../../app/middleware/workarea/enforce_host_middleware'
5671
app.config.middleware.use Workarea::EnforceHostMiddleware
5772

5873
# ApplicationMiddleware must wrap the entire Workarea request pipeline so it
5974
# can set up the Workarea::Visit, locale, and cache-key env vars before any
6075
# controller or caching layer runs.
76+
require_relative '../../app/middleware/workarea/application_middleware'
6177
app.config.middleware.insert(0, Workarea::ApplicationMiddleware)
6278

6379
# In test environments, strip all HTTP caching headers from responses so that
6480
# headless-browser tests behave consistently regardless of cache state.
81+
require_relative '../../app/middleware/workarea/strip_http_caching_middleware'
6582
app.config.middleware.insert(0, Workarea::StripHttpCachingMiddleware) if Rails.env.test?

0 commit comments

Comments
 (0)