Skip to content

Instantly share code, notes, and snippets.

@yuroyoro
Created March 18, 2016 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuroyoro/3302f062185e9366ab53 to your computer and use it in GitHub Desktop.
Save yuroyoro/3302f062185e9366ab53 to your computer and use it in GitHub Desktop.
任意のassetsのレスポンスヘッダにService-Worker-Allowdヘッダを追加するRack Middleware
class RackSwHeader
def initialize(app, config = [])
@app = app
@config = config
end
def call(env)
status, headers, body = @app.call env
path = env["PATH_INFO"]
@config.each do |entry|
next unless path == entry[:path]
headers["Service-Worker-Allowed"] = entry[:scope]
end
[status, headers, body]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment