Skip to content

Commit 1c33cc7

Browse files
authored
optimizer: Restore runtime-host path functionality (#1264)
PR #855 introduced two regressions: - It became impossible to specify a runtime-host with a path in the URL (e.g. https://example.com/amp-runtime) - The --rtv flag led to inconsistent AMP script URLs because runtime-host dropped /rtv/<rtv> One of the advertised features of self-hosting from https://github.com/ampproject/amphtml/blob/main/docs/spec/amp-framework-hosting.md is: - serve AMP pages and the framework from the same host, potentially improving content delivery times. For this to be possible, the runtime should be served from a path under the same domain as the amp pages.
1 parent 624c155 commit 1c33cc7

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

packages/optimizer/lib/transformers/RewriteAmpUrls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class RewriteAmpUrls {
129129
if (!this._usesAmpCacheUrl(host) && !params.lts) {
130130
try {
131131
const url = new URL(host);
132-
this._addMeta(head, 'runtime-host', url.origin);
132+
this._addMeta(head, 'runtime-host', url.origin + url.pathname);
133133
} catch (e) {
134134
this.log.warn('ampUrlPrefix must be an absolute URL');
135135
}

packages/optimizer/spec/end-to-end/hello-world/expected_output.paired.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width,minimum-scale=1">
6-
<meta name="runtime-host" content="https://example.com">
6+
<meta name="runtime-host" content="https://example.com/amp/rtv/123456789000000">
77
<meta name="amp-geo-api" content="/geo"><style amp-runtime i-amphtml-version="123456789000000">/* example.com v0.css */amp-img[i-amphtml-ssr]:not(.i-amphtml-element):not([layout=container])>*{display: block;}</style><script async src="https://example.com/amp/rtv/123456789000000/v0.mjs" type="module" crossorigin="anonymous"></script><script async nomodule src="https://example.com/amp/rtv/123456789000000/v0.js" crossorigin="anonymous"></script><script async custom-element="amp-experiment" src="https://example.com/amp/rtv/123456789000000/v0/amp-experiment-0.1.mjs" type="module" crossorigin="anonymous"></script><script async nomodule src="https://example.com/amp/rtv/123456789000000/v0/amp-experiment-0.1.js" crossorigin="anonymous" custom-element="amp-experiment"></script><script async custom-element="amp-analytics" src="https://example.com/amp/rtv/123456789000000/v0/amp-analytics-0.1.mjs" type="module" crossorigin="anonymous"></script><script async nomodule src="https://example.com/amp/rtv/123456789000000/v0/amp-analytics-0.1.js" crossorigin="anonymous" custom-element="amp-analytics"></script><script async custom-element="amp-video" src="https://example.com/amp/rtv/123456789000000/v0/amp-video-0.1.mjs" type="module" crossorigin="anonymous"></script><script async nomodule src="https://example.com/amp/rtv/123456789000000/v0/amp-video-0.1.js" crossorigin="anonymous" custom-element="amp-video"></script>
88
<link rel="canonical" href="self.html"><style amp-custom>h1{margin:16px}</style>
99
<link rel="amphtml" href="/amp-version.html">

0 commit comments

Comments
 (0)