mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
DEV: Simplify ember-cli proxy strategy (#24242)
Previously, the app HTML served by the Ember-CLI proxy was generated based on a 'bootstrap json' payload generated by Rails. This inevitably leads to differences between the Rails HTML and the Ember-CLI HTML. This commit overhauls our proxying strategy. Now, we totally ignore the ember-cli `index.html` file. Instead, we take the full HTML from Rails and surgically replace script URLs based on a `data-discourse-entrypoint` attribute. This should be faster (only one request to Rails), more robust, and less confusing for developers.
This commit is contained in:
@ -3,10 +3,10 @@
|
||||
|
||||
RSpec.describe ApplicationHelper do
|
||||
describe "preload_script" do
|
||||
def script_tag(url)
|
||||
def script_tag(url, entrypoint)
|
||||
<<~HTML
|
||||
<link rel="preload" href="#{url}" as="script">
|
||||
<script defer src="#{url}"></script>
|
||||
<link rel="preload" href="#{url}" as="script" data-discourse-entrypoint="#{entrypoint}">
|
||||
<script defer src="#{url}" data-discourse-entrypoint="#{entrypoint}"></script>
|
||||
HTML
|
||||
end
|
||||
|
||||
@ -57,33 +57,44 @@ RSpec.describe ApplicationHelper do
|
||||
helper.request.env["HTTP_ACCEPT_ENCODING"] = "br"
|
||||
link = helper.preload_script("start-discourse")
|
||||
|
||||
expect(link).to eq(script_tag("https://s3cdn.com/assets/start-discourse.br.js"))
|
||||
expect(link).to eq(
|
||||
script_tag("https://s3cdn.com/assets/start-discourse.br.js", "start-discourse"),
|
||||
)
|
||||
end
|
||||
|
||||
it "gives s3 cdn if asset host is not set" do
|
||||
link = helper.preload_script("start-discourse")
|
||||
|
||||
expect(link).to eq(script_tag("https://s3cdn.com/assets/start-discourse.js"))
|
||||
expect(link).to eq(
|
||||
script_tag("https://s3cdn.com/assets/start-discourse.js", "start-discourse"),
|
||||
)
|
||||
end
|
||||
|
||||
it "can fall back to gzip compression" do
|
||||
helper.request.env["HTTP_ACCEPT_ENCODING"] = "gzip"
|
||||
link = helper.preload_script("start-discourse")
|
||||
expect(link).to eq(script_tag("https://s3cdn.com/assets/start-discourse.gz.js"))
|
||||
expect(link).to eq(
|
||||
script_tag("https://s3cdn.com/assets/start-discourse.gz.js", "start-discourse"),
|
||||
)
|
||||
end
|
||||
|
||||
it "gives s3 cdn even if asset host is set" do
|
||||
set_cdn_url "https://awesome.com"
|
||||
link = helper.preload_script("start-discourse")
|
||||
|
||||
expect(link).to eq(script_tag("https://s3cdn.com/assets/start-discourse.js"))
|
||||
expect(link).to eq(
|
||||
script_tag("https://s3cdn.com/assets/start-discourse.js", "start-discourse"),
|
||||
)
|
||||
end
|
||||
|
||||
it "gives s3 cdn but without brotli/gzip extensions for theme tests assets" do
|
||||
helper.request.env["HTTP_ACCEPT_ENCODING"] = "gzip, br"
|
||||
link = helper.preload_script("discourse/tests/theme_qunit_ember_jquery")
|
||||
expect(link).to eq(
|
||||
script_tag("https://s3cdn.com/assets/discourse/tests/theme_qunit_ember_jquery.js"),
|
||||
script_tag(
|
||||
"https://s3cdn.com/assets/discourse/tests/theme_qunit_ember_jquery.js",
|
||||
"discourse/tests/theme_qunit_ember_jquery",
|
||||
),
|
||||
)
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user