Class: ShopifyCLI::Theme::DevServer::LocalAssets

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

Direct Known Subclasses

Extension::DevServer::LocalAssets

Defined Under Namespace

Classes: FileBody

Constant Summary collapse

THEME_REGEX =
%r{//cdn\.shopify\.com/s/.+?/(assets/.+?\.(?:css|js))}

Instance Method Summary collapse

Constructor Details

#initialize(ctx, app, target) ⇒ LocalAssets

Returns a new instance of LocalAssets.



25
26
27
28
29
# File 'lib/shopify_cli/theme/dev_server/local_assets.rb', line 25

def initialize(ctx, app, target)
  @ctx = ctx
  @app = app
  @target = target
end

Instance Method Details

#call(env) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/shopify_cli/theme/dev_server/local_assets.rb', line 31

def call(env)
  path_info = env["PATH_INFO"]
  if path_info.start_with?("/assets")
    # Serve from disk
    serve_file(path_info)
  else
    # Proxy the request, and replace the URLs in the response
    status, headers, body = @app.call(env)
    body = replace_asset_urls(body) unless path_info.start_with?("/fonts")
    [status, headers, body]
  end
end