-
-
Notifications
You must be signed in to change notification settings - Fork 97
Open
Description
Hey 👋 ,
I have following routes:
module MyApp
class Routes < Hanami::Routes
root { "Hello from MyApp-server" }
slice :payments, at: "/payments" do
use :body_parser, :json # json body-parser should be used for all payments-requests.
scope :auth do
post "/login", to: "auth.login"
end
scope :graphql do
use MyApp::Middlewares::Authorization
post "/api", to: "graphql.api"
end
end
end
endIt is expected that the json-body-parser is applied to all payment requests, regardless if payments/auth/login or payments/graphql/api is requested. But that's not the case. The body payload of a payments/auth/login is not parsed and fails. A request to payments/graphql/api is parsed and runs through the MyApp::Middlewares::Authorization-middlware.
user@6beeaaf00e22:~/app$ bin/hanami middleware
/ Dry::Monitor::Rack::Middleware (instance)
/ Rack::Session::Cookie
/payments Hanami::Middleware::BodyParser
/payments/graphql PayNRed::Middlewares::AuthorizationIf I remove the MyApp::Middlewares::Authorization-middleware, the body-parsing for payments/auth/login and payments/graphql/api works as expected.
To make it work, I had to change the routes to following:
module MyApp
class Routes < Hanami::Routes
root { "Hello from MyApp-server" }
slice :payments, at: "/payments" do
scope :auth do
use :body_parser, :json # json body-parser should be used for all payments-requests.
post "/login", to: "auth.login"
end
scope :graphql do
use :body_parser, :json # json body-parser should be used for all payments-requests.
use MyApp::Middlewares::Authorization
post "/api", to: "graphql.api"
end
end
end
enduser@6beeaaf00e22:~/app$ bin/hanami middleware
/ Dry::Monitor::Rack::Middleware (instance)
/ Rack::Session::Cookie
/payments/auth Hanami::Middleware::BodyParser
/payments/graphql Hanami::Middleware::BodyParser
/payments/graphql PayNRed::Middlewares::AuthorizationIs this the expected behavior?
Thanks and best regards
Metadata
Metadata
Assignees
Labels
No labels