Created
August 22, 2018 19:55
-
-
Save danielrozenberg/95cc0cc4b84810132396fca687d42f04 to your computer and use it in GitHub Desktop.
Rewrite the AMP runtime library so that extensions loaded by the Shadow embed code will be loaded from localhost, not from the CDN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/service/extensions-impl.js b/src/service/extensions-impl.js | |
index e6116b8ec..d40ea8ad8 100644 | |
--- a/src/service/extensions-impl.js | |
+++ b/src/service/extensions-impl.js | |
@@ -556,6 +556,7 @@ export class Extensions { | |
if (this.isExtensionScriptRequired_(extensionId, holder)) { | |
const scriptElement = | |
this.createExtensionScript_(extensionId, opt_extensionVersion); | |
+ scriptElement.src = scriptElement.src.replace(/https:\/\/cdn.ampproject.org\/rtv\/\d+\//, 'http://localhost:8000/dist/'); | |
this.win.document.head.appendChild(scriptElement); | |
holder.scriptPresent = true; | |
} | |
diff --git a/src/service/xhr-impl.js b/src/service/xhr-impl.js | |
index 3ed4c0cb6..71c197bb1 100644 | |
--- a/src/service/xhr-impl.js | |
+++ b/src/service/xhr-impl.js | |
@@ -157,6 +157,9 @@ export class Xhr { | |
if (init.responseType == 'document') { | |
return fetchPolyfill(input, init); | |
} | |
+ if (arguments.length && arguments[0].endsWith('/ww.js')) { | |
+ arguments[0] = 'http://localhost:8000/dist/ww.js'; | |
+ } | |
return (this.win.fetch || fetchPolyfill).apply(null, arguments); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment