DEV: Allow accessing sourcemaps on `/brotli_asset` path (#19894)

Our JS files reference sourcemaps relative to their current path. On sites with non-S3 CDN setups, we use a special path for brotli assets (39a524aa). This caused the sourcemap requests to 404.

This commit fixes the issue by allowing the `.map` files to be accessed under `/brotli_asset/*`.
This commit is contained in:
David Taylor 2023-01-17 12:49:42 +00:00 committed by GitHub
parent ef437a1e41
commit 4204b984ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -193,8 +193,12 @@ class StaticController < ApplicationController
def brotli_asset
is_asset_path
if params[:path].end_with?(".map")
serve_asset
else
serve_asset(".br") { response.headers["Content-Encoding"] = "br" }
end
end
def cdn_asset
is_asset_path

View File

@ -122,6 +122,22 @@ RSpec.describe StaticController do
File.delete(file_path)
end
end
it "can serve sourcemaps on adjacent paths" do
assets_path = Rails.root.join("public/assets")
FileUtils.mkdir_p(assets_path)
file_path = assets_path.join("test.map")
File.write(file_path, "fake source map")
GlobalSetting.stubs(:cdn_url).returns("https://www.example.com/")
get "/brotli_asset/test.map"
expect(response.status).to eq(200)
ensure
File.delete(file_path)
end
end
describe "#cdn_asset" do