Handle missing sw.js in test environment assets (#39459)
This commit is contained in:
parent
eba056979f
commit
41ea9ad128
@ -5,8 +5,9 @@ require 'action_dispatch/middleware/static'
|
|||||||
module Mastodon
|
module Mastodon
|
||||||
module Middleware
|
module Middleware
|
||||||
class PublicFileServer
|
class PublicFileServer
|
||||||
|
CACHE_TTL = 28.days.to_i
|
||||||
|
SERVICE_WORKER_PATH = '/sw.js'
|
||||||
SERVICE_WORKER_TTL = 7.days.to_i
|
SERVICE_WORKER_TTL = 7.days.to_i
|
||||||
CACHE_TTL = 28.days.to_i
|
|
||||||
|
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
@app = app
|
@app = app
|
||||||
@ -24,7 +25,7 @@ module Mastodon
|
|||||||
# Set cache headers on static files. Some paths require different cache headers
|
# Set cache headers on static files. Some paths require different cache headers
|
||||||
request = Rack::Request.new env
|
request = Rack::Request.new env
|
||||||
headers['cache-control'] = begin
|
headers['cache-control'] = begin
|
||||||
if request.path.start_with?('/sw.js')
|
if request.path.start_with?(SERVICE_WORKER_PATH)
|
||||||
"public, max-age=#{SERVICE_WORKER_TTL}, must-revalidate"
|
"public, max-age=#{SERVICE_WORKER_TTL}, must-revalidate"
|
||||||
elsif request.path.start_with?(paperclip_root_url)
|
elsif request.path.start_with?(paperclip_root_url)
|
||||||
"public, max-age=#{CACHE_TTL}, immutable"
|
"public, max-age=#{CACHE_TTL}, immutable"
|
||||||
|
|||||||
@ -6,8 +6,10 @@ RSpec.describe 'Public files' do
|
|||||||
include RoutingHelper
|
include RoutingHelper
|
||||||
|
|
||||||
context 'when requesting service worker file' do
|
context 'when requesting service worker file' do
|
||||||
|
before { stub_const 'Mastodon::Middleware::PublicFileServer::SERVICE_WORKER_PATH', '/robots.txt' }
|
||||||
|
|
||||||
it 'returns the file with the expected headers' do
|
it 'returns the file with the expected headers' do
|
||||||
get '/sw.js'
|
get Mastodon::Middleware::PublicFileServer::SERVICE_WORKER_PATH
|
||||||
|
|
||||||
expect(response)
|
expect(response)
|
||||||
.to have_http_status(200)
|
.to have_http_status(200)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user