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

Function passthroughServeModeCdn

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

* Respond with content received from a URL when SERVE_MODE is "cdn". * @param {express.Response} res * @param {string} cdnUrl * @return {Promise }

(res, cdnUrl)

Source from the content-addressed store, hash-verified

47 * @return {Promise<boolean>}
48 */
49async function passthroughServeModeCdn(res, cdnUrl) {
50 if (SERVE_MODE !== 'cdn') {
51 return false;
52 }
53 try {
54 const response = await fetch(cdnUrl);
55 res.status(response.status);
56 res.send(await response.text());
57 } catch (e) {
58 log(red('ERROR:'), e);
59 res.status(500);
60 res.end();
61 }
62 return true;
63}
64
65const app = express();
66const TEST_SERVER_PORT = argv.port || 8000;

Callers 1

app.jsFile · 0.85

Calls 5

fetchFunction · 0.85
redFunction · 0.85
logFunction · 0.70
sendMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected