MCPcopy
hub / github.com/ampproject/amphtml / requestAmphtmlDocUrl

Function requestAmphtmlDocUrl

build-system/server/app.js:197–213  ·  view source on GitHub ↗

* Resolves an AMPHTML URL from a canonical URL. If AMPHTML is canonical, same * URL is returned. * @param {string} urlSuffix URL without protocol or google.com/amp/s/... * @param {string=} protocol 'https' or 'http'. 'https' retries using 'http'. * @return {!Promise }

(urlSuffix, protocol = 'https')

Source from the content-addressed store, hash-verified

195 * @return {!Promise<string>}
196 */
197async function requestAmphtmlDocUrl(urlSuffix, protocol = 'https') {
198 const defaultUrl = `${protocol}://${urlSuffix}`;
199 logWithoutTimestamp(`Fetching URL: ${defaultUrl}`);
200
201 const response = await fetch(defaultUrl);
202 if (!response.ok) {
203 if (protocol == 'https') {
204 return requestAmphtmlDocUrl(urlSuffix, 'http');
205 }
206 throw new Error(`Status: ${response.status}`);
207 }
208
209 const {window} = new jsdom.JSDOM(await response.text());
210 const linkRelAmphtml = window.document.querySelector('link[rel=amphtml]');
211 const amphtmlUrl = linkRelAmphtml && linkRelAmphtml.getAttribute('href');
212 return amphtmlUrl || defaultUrl;
213}
214
215/*
216 * Intercept Recaptcha frame for,

Callers 1

app.jsFile · 0.85

Calls 4

logWithoutTimestampFunction · 0.85
fetchFunction · 0.85
getAttributeMethod · 0.80
textMethod · 0.45

Tested by

no test coverage detected