Class: ShopifyCLI::Theme::DevServer::CdnFonts

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify_cli/theme/dev_server/cdn_fonts.rb

Constant Summary collapse

FONTS_PATH =
"/fonts"
FONTS_CDN =
"https://fonts.shopifycdn.com"
FONTS_REGEX =
%r{#{FONTS_CDN}}

Instance Method Summary collapse

Constructor Details

#initialize(app, theme:) ⇒ CdnFonts

Returns a new instance of CdnFonts.



11
12
13
14
# File 'lib/shopify_cli/theme/dev_server/cdn_fonts.rb', line 11

def initialize(app, theme:)
  @app = app
  @theme = theme
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/shopify_cli/theme/dev_server/cdn_fonts.rb', line 16

def call(env)
  path = env["PATH_INFO"]

  # Serve from fonts CDN
  return serve_font(env) if path.start_with?(FONTS_PATH)

  # Proxy the request, and replace the URLs in the response
  status, headers, body = @app.call(env)
  body = replace_font_urls(body)
  [status, headers, body]
end