Skip to content

Namespace egine routes #1965

@jabawack81

Description

@jabawack81

Issue summary

Before opening this issue, I have done the following:

  • Upgraded to the latest version of the package
    • shopify_app version: 22.5.2
    • Ruby version: 3.3.0
    • Operating system: Arch Linux
  • Set log_level: :debug in 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

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.

get "logout" => :destroy, :as => :logout
get "patch_shopify_id_token" => :patch_shopify_id_token

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

  1. Add a namespace around the mount engine in the config/routes.rb
  2. Run the command rails routes

Debug logs

// Paste any relevant logs here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions