Skip to content

Commit

Permalink
fix: call to default middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
aristotelesbr committed Dec 19, 2023
1 parent 71232fe commit 57ca429
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/lenna/middleware/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def fetch_or_build_middleware_chain(
# chain.
#
def build_middleware_chain(action, middlewares)
all_middlewares = (@global_middlewares + Array(middlewares)).uniq
all_middlewares = (@global_middlewares + Array(middlewares))

all_middlewares.reverse.reduce(action) do |next_middleware, middleware|
->(req, res) {
Expand Down
16 changes: 6 additions & 10 deletions lib/lenna/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ def initialize(
@middleware_manager = middleware_manager
@namespace_stack = NamespaceStack.new
@roter_builder = Builder.new(@root_node)

default_milddlewares = [
Middleware::Default::Logging,
Middleware::Default::ErrorHandler
]

@middleware_manager.use(default_milddlewares) unless @default_milddlewares
@default_milddlewares = true
end

# This method is used to add a namespace to the routes.
Expand Down Expand Up @@ -114,7 +106,7 @@ def namespace(prefix, &block)
#
# @parameter middlewares [Array] the middlewares to be used
#
# @return [void]
# @return [void]
#
def use(*middlewares) = @middleware_manager.use(middlewares)

Expand All @@ -136,7 +128,11 @@ def call(env) = dup.call!(env)
#
def call!(env)
middleware_pipeline = @middleware_manager.fetch_or_build_middleware_chain(
method(:process_request), []
method(:process_request),
[
Middleware::Default::Logging,
Middleware::Default::ErrorHandler
]
)

req = Request.new(env)
Expand Down

0 comments on commit 57ca429

Please sign in to comment.