Namespace egine routes
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 1.9k
- Forks
- 739
- Avg merge
- 21h 2m
- Merged PRs (30d)
- 1
Description
Issue summary
Before opening this issue, I have done the following:
- Upgraded to the latest version of the package
shopify_appversion:22.5.2- Ruby version:
3.3.0 - Operating system: Arch Linux
- Set
log_level: :debugin my configuration, if applicable - Found a reliable way to reproduce the problem that indicates it's a problem with the package
- Looked for similar issues in this repository
- Checked that this isn't an issue with a Shopify API
- If it is, please create a post in the Shopify community forums or report it to Shopify Partner Support
My shopify app needs to have a separate admin section where our admin will be able to handle our customers data, so I planned to namespace all the ShopifyApp with something like /shopify/ and leave the top level routes for our internal dashboard so I tried to wrap all the routes created by the rials template in a namespace like:
# frozen_string_literal: true
Rails.application.routes.draw do
namespace :shopify do
root to: "home#index"
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
scope path: :api, format: :json do
# POST /api/products and GET /api/products/count
resources :products, only: :create do
collection do
get :count
end
end
namespace :webhooks do
post "/app_uninstalled", to: "app_uninstalled#receive"
post "/app_scopes_update", to: "app_scopes_update#receive"
post "/customers_data_request", to: "customers_data_request#receive"
post "/customers_redact", to: "customers_redact#receive"
post "/shop_redact", to: "shop_redact#receive"
end
# Health check routes
end
mount ShopifyApp::Engine, at: "/api"
get "/api", to: redirect(path: "/") # Needed because our engine root is /api but that breaks frontend routing
# If you are adding routes outside of the /api path, remember to also add a proxy rule for
# them in web/frontend/vite.config.js
# Any other routes will just render the react app
match "*path" => "shopify/home#index", via: %i[get post]
end
get "health", to: "health#index"
get "health/detailed", to: "health#detailed"
root to: "dashboard#index"
end
Checking the routes with rails route, I noticed that all the routes generated by the ShopifyApp engine are still not namespace. I spent several hours trying to set up the config.root_url and the at: "/api" in the engine mount to various properties in the engine initialisers, but this didn't help. Then I noticed that some of the paths are even hardcoded and not configurable.
Expected behavior
All the routes generated by the engine should be namespaced.
Actual behavior
all the routes are not namespaced
Steps to reproduce the problem
- Add a namespace around the mount engine in the
config/routes.rb - Run the command
rails routes
Debug logs
// Paste any relevant logs here
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The engine routes are defined in config/routes.rb at the linked lines; first reproduce the namespace setup and inspect the output from rails routes. Trace how the mounted engine's paths are built, then verify that every generated route carries the requested namespace without breaking the documented application routes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100