更改shopify_app gem的引擎路线

时间:2017-06-10 04:53:57

标签: ruby-on-rails routes shopify

我正在使用带有rails 5的shopify_app gem。我希望shopify_app能够从嵌套路由中运行。例如:/ shopify_app / login或' / shopify_app / auth / shopify / callback'。

我尝试了gem文档中给出的解决方案,并将这些行放在我的routes.rb文件中:

mount ShopifyApp::Engine, at: 'shopify_app'  
get '/shopify_app' => 'settings#index'

Routes for shopify_app root Routes for shopify_app engine

但它并没有这样做。所以我用Google搜索并找到了一个解决方案,通过在omniauth初始化程序中进行一些更改来使其工作。

Rails.application.config.middleware.use OmniAuth::Builder do
    provider :shopify, ShopifyApp.configuration.api_key, ShopifyApp.configuration.secret, scope: ShopifyApp.configuration.scope, callback_path: '/shopify_app/auth/shopify/callback'
end

以下是应用设置:

Embedded App SDK:已启用

App Url:https://salebait.com/settings

白名单重定向网址:https://salebait.com/shopify_app/auth/shopify/callback

现在问题是,当我第一次安装我的应用时,它会在安装后重定向到我网站的主页(https://salebait.com),但它应该在商店管理员中打开https://salebait.com/settings页面。如果我关闭浏览器或从商店注销并再次返回应用程序,则转到https://salebait.com/login这不是有效页面,因为所有应用程序路径都包含在/ shopify_app /内,因此应用程序的登录URL应该是https://salebait.com/shopify_app/login。 然后我必须手动点击应用程序的登录URL才能使其正常工作。

请建议一些解决方案,让我的应用路线顺利运作。

编辑:如果尝试在其他浏览器中打开应用程序,应用程序会重定向到错误的登录页面。以下是错误屏幕: enter image description here

感谢。

1 个答案:

答案 0 :(得分:2)

如果其他人正在寻找解决方案,那么它是: 我正在将shopify_app引擎安装在" / shopify_app"命名空间。但它是gem的默认命名空间,因此它不会覆盖默认路由。

所以我将shopify_app命名空间更改为" / app"它运作顺利。

mount ShopifyApp::Engine, at: 'app'  
get '/app' => 'settings#index'

还更改了Omniauth构建器和应用程序设置中的路径。

Rails.application.config.middleware.use OmniAuth::Builder do
    provider :shopify, ShopifyApp.configuration.api_key, ShopifyApp.configuration.secret, scope: ShopifyApp.configuration.scope, callback_path: '/app/auth/shopify/callback'
end
相关问题