Hi, I have some routes not getting created in the api gateway. Running the app server locally they work correctly, and they show up correctly for “jets routes”. I’m pretty sure I’m simply missing a rails convention, but havent been able to solve it yet.
Basically I have a SearchController, and want several POST requests mapped to the methods, eg “reports” go to “search#get_reports”, “categories” go to “search#get_categories”. They are API style queries, so have various parameters passed in.
What’s the convention I’m missing to have a controller have several POST handlers? Or, why might a route be skipped by “jets deploy” ?
Thanks Tung, I’ll keep poking. Here’s my routes.rb
Update: looks like it’s the authorizer. Removing it gets the API created correctly, and there’s an error in the deploy (sorry, missed this earlier):
ERROR: Template error: instance of Fn::GetAtt references undefined resource ApplicationAuthorizer
I’ll update when I figure it out.
Jets.application.routes.draw do
post "status", to: "search#status", authorizer: "application#protect"
post "searchcriteria", to: "search#getSearchCriteria", authorizer: "application#protect"
post "dbstatus", to: "search#db_status", authorizer: "application#protect"
post "search", to: "search#search", authorizer: "application#protect"
post "usersreports", to: "search#users_reports", authorizer: "application#protect"
post "dealercodes", to: "search#getDealerCodes", authorizer: "application#protect"
get "download/:id", to: "search#download", authorizer: "application#protect"
post "user/info", to: "user#userInfo", authorizer: "application#protect"
end
What’s your app/authorizers/application_authorizer.rb look like? A demo repo may help.
Also, here’s a tip. You may be able to clean up the routes file by declaring the authorizer in the ApplicationController:
class ApplicationController < Jets::Controller::Base
authorizer "application#protect"
end
Then you won’t need the authorizer on every single route. If you have some routes that don’t require the authorizer, maybe create another controller that all protected controllers inherit from. There is currently no skip_authorizer macro yet.
class ApplicationAuthorizer < ApplicationAuthorizer
authorizer(
name: "CognitoAuthorizer", # <= name is used as the "function" name
identity_source: "Authorization", # maps to method.request.header.Authorization
type: :cognito_user_pools,
provider_arns: [
ENV['COGNITO_USER_POOL_ARN']
]
)
end
Good call on the class-wide authorizer. That works for me.
Ack, my mistake! My routes should have been “application#cognito_authorizer”, NOT application#protect. Doh! Thanks for checking on this Tung, really appreciated! Good tip on class-wide authorizer.