Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Revert "Fix CORS (Cross-origin resource sharing) errors (#1952)" (#1985)
Browse files Browse the repository at this point in the history
  • Loading branch information
karreiro authored Jan 28, 2022
1 parent 9ec90b9 commit 47fb451
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 384 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
From version 2.6.0, the sections in this file adhere to the [keep a changelog](https://keepachangelog.com/en/1.0.0/) specification.

## [Unreleased]
### Fixed
* [#1985](https://github.com/Shopify/shopify-cli/pull/1985): Revert "Fix CORS (Cross-origin resource sharing) errors (#1952)"

## Version 2.10.0
### Fixed
Expand Down
2 changes: 0 additions & 2 deletions lib/shopify_cli/theme/dev_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require_relative "ignore_filter"
require_relative "syncer"

require_relative "dev_server/cdn_assets"
require_relative "dev_server/cdn_fonts"
require_relative "dev_server/hot_reload"
require_relative "dev_server/header_hash"
Expand Down Expand Up @@ -38,7 +37,6 @@ def start(ctx, root, host: "127.0.0.1", port: 9292, poll: false, mode: ReloadMod
@app = Proxy.new(ctx, theme: theme, syncer: @syncer)
@app = CdnFonts.new(@app, theme: theme)
@app = LocalAssets.new(ctx, @app, theme: theme)
@app = CdnAssets.new(@app, theme: theme)
@app = HotReload.new(ctx, @app, theme: theme, watcher: watcher, mode: mode, ignore_filter: ignore_filter)
stopped = false
address = "http://#{host}:#{port}"
Expand Down
49 changes: 0 additions & 49 deletions lib/shopify_cli/theme/dev_server/cdn/cdn_helper.rb

This file was deleted.

69 changes: 0 additions & 69 deletions lib/shopify_cli/theme/dev_server/cdn_assets.rb

This file was deleted.

36 changes: 28 additions & 8 deletions lib/shopify_cli/theme/dev_server/cdn_fonts.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
# frozen_string_literal: true

require_relative "cdn/cdn_helper"

module ShopifyCLI
module Theme
module DevServer
class CdnFonts
include Cdn::CdnHelper

FONTS_PATH = "/fonts"
FONTS_CDN = "https://fonts.shopifycdn.com"
FONTS_REGEX = %r{#{FONTS_CDN}}
Expand All @@ -21,7 +17,7 @@ def call(env)
path = env["PATH_INFO"]

# Serve from fonts CDN
return serve_font(env, path) if path.start_with?(FONTS_PATH)
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)
Expand All @@ -31,11 +27,35 @@ def call(env)

private

def serve_font(env, path)
query = env["QUERY_STRING"]
def serve_font(env)
parameters = %w(PATH_INFO QUERY_STRING REQUEST_METHOD rack.input)
path, query, method, body_stream = *env.slice(*parameters).values

uri = fonts_cdn_uri(path, query)

proxy_request(env, uri, @theme)
response = Net::HTTP.start(uri.host, 443, use_ssl: true) do |http|
req_class = Net::HTTP.const_get(method.capitalize)
req = req_class.new(uri)
req.initialize_http_header(fonts_cdn_headers)
req.body_stream = body_stream
http.request(req)
end

[
response.code.to_s,
{
"Content-Type" => response.content_type,
"Content-Length" => response.content_length.to_s,
},
[response.body],
]
end

def fonts_cdn_headers
{
"Referer" => "https://#{@theme.shop}",
"Transfer-Encoding" => "chunked",
}
end

def fonts_cdn_uri(path, query)
Expand Down
4 changes: 0 additions & 4 deletions lib/shopify_cli/theme/dev_server/local_assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ def initialize(path)
@path = path
end

def join
@path.read
end

# Naive implementation. Only used in unit tests.
def each
yield @path.read
Expand Down
64 changes: 0 additions & 64 deletions test/shopify-cli/theme/dev_server/cdn/cdn_helper_test.rb

This file was deleted.

Loading

0 comments on commit 47fb451

Please sign in to comment.