mirror of
https://github.com/we-promise/sure.git
synced 2026-05-27 22:44:55 +00:00
fix(pwa): serve manifest for html accept headers (#1828)
* fix(pwa): serve manifest for html accept headers * style: add trailing newline to pwa controller
This commit is contained in:
15
app/controllers/pwa_controller.rb
Normal file
15
app/controllers/pwa_controller.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class PwaController < ApplicationController
|
||||
skip_authentication
|
||||
|
||||
def manifest
|
||||
# Force JSON format to avoid MissingTemplate errors when browsers request /manifest
|
||||
# with HTML Accept headers (Safari Mobile does this for PWA manifest discovery)
|
||||
render "pwa/manifest", content_type: "application/manifest+json"
|
||||
end
|
||||
|
||||
def service_worker
|
||||
# Explicitly render JS template to avoid format negotiation issues
|
||||
render "pwa/service-worker", content_type: "application/javascript"
|
||||
end
|
||||
# Renders app/views/pwa/service-worker.js with content type application/javascript
|
||||
end
|
||||
@@ -641,8 +641,8 @@ Rails.application.routes.draw do
|
||||
get "up" => "rails/health#show", as: :rails_health_check
|
||||
|
||||
# Render dynamic PWA files from app/views/pwa/*
|
||||
get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker
|
||||
get "manifest" => "rails/pwa#manifest", as: :pwa_manifest
|
||||
get "service-worker" => "pwa#service_worker", as: :pwa_service_worker, defaults: { format: :js }
|
||||
get "manifest" => "pwa#manifest", as: :pwa_manifest, defaults: { format: :json }
|
||||
|
||||
get "imports/:import_id/upload/sample_csv", to: "import/uploads#sample_csv", as: :import_upload_sample_csv
|
||||
|
||||
|
||||
11
test/controllers/pwa_controller_test.rb
Normal file
11
test/controllers/pwa_controller_test.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
require "test_helper"
|
||||
|
||||
class PwaControllerTest < ActionDispatch::IntegrationTest
|
||||
test "manifest responds successfully for html accept headers" do
|
||||
get "/manifest", headers: { "Accept" => "text/html" }
|
||||
|
||||
assert_response :success
|
||||
assert_equal "application/manifest+json", response.media_type
|
||||
assert_includes response.body, '"start_url": "/"'
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user