Skip to content

Improve engine routes installation#2076

Open
kennyadsl wants to merge 5 commits into
Shopify:mainfrom
nebulab:nebulab/improve-install-routes
Open

Improve engine routes installation#2076
kennyadsl wants to merge 5 commits into
Shopify:mainfrom
nebulab:nebulab/improve-install-routes

Conversation

@kennyadsl
Copy link
Copy Markdown
Contributor

What this PR does

This pull request refactors how routes are generated and managed in the Shopify App generators. The main focus is on simplifying and modernizing route injection, removing legacy route generator code, and improving the setup of webhook routes. Below are the most important changes:

Route Generation Refactoring

  • Removed the legacy RoutesGenerator and its associated template and tests, eliminating the custom logic for injecting ShopifyApp routes and disabling engine routes.
  • Updated the add_webhook_route method to use the Rails route helper with namespacing instead of directly injecting lines into routes.rb, making the code more idiomatic and maintainable.
  • Added a new setup_routes method in the install generator to scaffold a namespaced section for webhook routes, providing clearer guidance for developers.

Test and Template Updates

  • Updated test and dummy application route files to reflect the new approach, ensuring webhook routes are properly namespaced, and the engine is mounted in a consistent location.

Reviewer's guide to testing

Currently, if you create a new app, run the install generator and then run:

rails g shopify_app:add_declarative_webhook --topic carts/update --path webhooks/carts_update

It won't work, as the webhooks namespace is not present in the routes file.

With this change, it works.

Checklist

Before submitting the PR, please consider if any of the following are needed:

  • Update CHANGELOG.md if the changes would impact users
  • Update README.md, if appropriate.
  • Update any relevant pages in /docs, if necessary
  • For security fixes, the Disclosure Policy must be followed.

kennyadsl added 5 commits May 18, 2026 22:40
This test is now failing, as it wasn't matching the route because it was
using different style of quote in the fixture at test/app_templates/config/routes.rb:

    mount ShopifyApp::Engine, at: "/"

This commit just exposes some lack in this generator.
This generator seems to be useless:

- The routes it's injecting in the host routes file are already in the
  engine's routes, and they are configurable. See config/routes.rb
- It seems it has been created as alternative approach to the engine's
  routes but the generator was not removing them correctly, so it wasn't
  working as expected. See previous commit for more details.
- The routes template for this generator seems to be out to date. I
  doubt someone used it recently.

Removing this path for routes  makes the application code cleaner and
creates a unique way of handling routes.
If we want to inject declarative webhook routes into the host
application, it's a good idea to setup routes to have it from the
beginning.

This commit add this namespace to the routes, and align all the fixture
files to be as similar as possible to a brand new host application after
the install.

After the install, a host app routes file looks like this:

Rails.application.routes.draw do
  root :to => 'home#index'
  get '/products', :to => 'products#index'
  namespace :webhooks do
    # Add your webhook routes here
  end
  mount ShopifyApp::Engine, at: '/'
@github-actions github-actions Bot added the devtools-gardener Post the issue or PR to Slack for the gardener label May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devtools-gardener Post the issue or PR to Slack for the gardener

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant