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:
Sure Admin (bot)
2026-05-18 19:10:01 +02:00
committed by GitHub
parent 4fd460d551
commit b73da38f49
3 changed files with 28 additions and 2 deletions

View 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

View File

@@ -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

View 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