前提・実現したいこと
RailsとOneSignalでのWebPush通知においてエラーを解消したいです。
ただし、動作は問題なくpush通知ができていることを確認しています。
発生している問題・エラーメッセージ
OneSignalのドキュメントを参考に実装しました。
特記事項として、今回の問題に関係している設定は以下の通りです。
- step2 Site Setup
「My Site is Not Fully HTTPS」を選択
- step6 Upload OneSignal SDK
step2で「My Site is Not Fully HTTPS」を選択したので不要ということでスキップ
その後、WebPush通知アイコンを表示しているページにアクセスすると、Railsサーバのログに以下のメッセージが表示されます。
Started GET "/OneSignalSDKUpdaterWorker.js?appId=0a9012ce-0681-4c1d-9681-9d29add0c5e7" for ::1 at 2021-06-08 12:06:26 +0900 ActionController::RoutingError (No route matches [GET] "/OneSignalSDKUpdaterWorker.js"): actionpack (5.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call' web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app' web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call' web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch' web-console (3.7.0) lib/web_console/middleware.rb:20:in `call' actionpack (5.2.5) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call' railties (5.2.5) lib/rails/rack/logger.rb:38:in `call_app' railties (5.2.5) lib/rails/rack/logger.rb:26:in `block in call' activesupport (5.2.5) lib/active_support/tagged_logging.rb:71:in `block in tagged' activesupport (5.2.5) lib/active_support/tagged_logging.rb:28:in `tagged' activesupport (5.2.5) lib/active_support/tagged_logging.rb:71:in `tagged' railties (5.2.5) lib/rails/rack/logger.rb:26:in `call' sprockets-rails (3.2.2) lib/sprockets/rails/quiet_assets.rb:13:in `call' actionpack (5.2.5) lib/action_dispatch/middleware/remote_ip.rb:81:in `call' request_store (1.5.0) lib/request_store/middleware.rb:19:in `call' actionpack (5.2.5) lib/action_dispatch/middleware/request_id.rb:27:in `call' rack (2.2.3) lib/rack/method_override.rb:24:in `call' rack (2.2.3) lib/rack/runtime.rb:22:in `call' activesupport (5.2.5) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' actionpack (5.2.5) lib/action_dispatch/middleware/executor.rb:14:in `call' actionpack (5.2.5) lib/action_dispatch/middleware/static.rb:127:in `call' rack (2.2.3) lib/rack/sendfile.rb:110:in `call' railties (5.2.5) lib/rails/engine.rb:524:in `call' puma (3.12.6) lib/puma/configuration.rb:227:in `call' puma (3.12.6) lib/puma/server.rb:706:in `handle_request' puma (3.12.6) lib/puma/server.rb:476:in `process_client' puma (3.12.6) lib/puma/server.rb:334:in `block in run' puma (3.12.6) lib/puma/thread_pool.rb:135:in `block in spawn_thread' Started GET "/OneSignalSDKUpdaterWorker.js?appId=0a9012ce-0681-4c1d-9681-9d29add0c5e7" for ::1 at 2021-06-08 12:06:27 +0900 ActionController::RoutingError (No route matches [GET] "/OneSignalSDKUpdaterWorker.js"): actionpack (5.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call' web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app' web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call' web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch' web-console (3.7.0) lib/web_console/middleware.rb:20:in `call' actionpack (5.2.5) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call' railties (5.2.5) lib/rails/rack/logger.rb:38:in `call_app' railties (5.2.5) lib/rails/rack/logger.rb:26:in `block in call' activesupport (5.2.5) lib/active_support/tagged_logging.rb:71:in `block in tagged' activesupport (5.2.5) lib/active_support/tagged_logging.rb:28:in `tagged' activesupport (5.2.5) lib/active_support/tagged_logging.rb:71:in `tagged' railties (5.2.5) lib/rails/rack/logger.rb:26:in `call' sprockets-rails (3.2.2) lib/sprockets/rails/quiet_assets.rb:13:in `call' actionpack (5.2.5) lib/action_dispatch/middleware/remote_ip.rb:81:in `call' request_store (1.5.0) lib/request_store/middleware.rb:19:in `call' actionpack (5.2.5) lib/action_dispatch/middleware/request_id.rb:27:in `call' rack (2.2.3) lib/rack/method_override.rb:24:in `call' rack (2.2.3) lib/rack/runtime.rb:22:in `call' activesupport (5.2.5) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' actionpack (5.2.5) lib/action_dispatch/middleware/executor.rb:14:in `call' actionpack (5.2.5) lib/action_dispatch/middleware/static.rb:127:in `call' rack (2.2.3) lib/rack/sendfile.rb:110:in `call' railties (5.2.5) lib/rails/engine.rb:524:in `call' puma (3.12.6) lib/puma/configuration.rb:227:in `call' puma (3.12.6) lib/puma/server.rb:706:in `handle_request' puma (3.12.6) lib/puma/server.rb:476:in `process_client' puma (3.12.6) lib/puma/server.rb:334:in `block in run' puma (3.12.6) lib/puma/thread_pool.rb:135:in `block in spawn_thread'
該当のソースコード
Rails
1<!DOCTYPE html> 2<html> 3 <head> 4 <title>SampleOnesignal</title> 5 <%= csrf_meta_tags %> 6 <%= csp_meta_tag %> 7 <%= include_gon %> 8 9 <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> 10 <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> 11 12 13 <script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async=""></script> 14 <script> 15 window.OneSignal = window.OneSignal || []; 16 OneSignal.push(function() { 17 OneSignal.init({ 18 appId: <発行されたapp_id>, 19 }); 20 }); 21 </script> 22 23 </head> 24 25 <body> 26 <%= yield %> 27 </body> 28</html> 29
試したこと
OneSignalのドキュメントで不要と記述されている「Step 6. Upload OneSignal SDK」を実施するとエラーは発生しなくなります。
具体的にはpublicディレクトリ内に以下の2ファイルを配置しました。
- OneSignalSDKWorker.js
- OneSignalSDKUpdaterWorker.js
補足情報(FW/ツールのバージョンなど)
- Mac Catalina 10.15.7
- Ruby 2.6.3
- Rails 5.2.5
あなたの回答
tips
プレビュー