-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6da9c0
commit c574def
Showing
11 changed files
with
23 additions
and
40 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export async function handleHttpRequest(request, context) { | ||
const baseReplacementUrl = 'https://cdnjs.cloudflare.com'; | ||
const srcPrefixes = [ | ||
'https://polyfill.io', | ||
'http://polyfill.io', | ||
'//polyfill.io', | ||
]; | ||
|
||
const transformerDefinitions = srcPrefixes.map((prefix) => ({ | ||
selector: `script[src^="${prefix}"]`, | ||
element: async (el) => { | ||
const src = el.get_attribute('src'); | ||
el.set_attribute('src', src.replace(prefix, baseReplacementUrl)); | ||
}, | ||
})); | ||
|
||
// Serve the origin response, transforming the HTML content to replace the polyfill.io script tag(s) | ||
return fetch(request.url, { edgio: { origin: 'my-origin' } }).then( | ||
(response) => HtmlTransformer.stream(transformerDefinitions, response) | ||
); | ||
} |
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "edgio-polyfill.io-replace-example", | ||
"name": "edgio-polyfill_io-replace-example", | ||
"version": "1.0.0", | ||
"description": "", | ||
"scripts": { | ||
|
@@ -17,4 +17,4 @@ | |
"@edgio/prefetch": "^7.12.5" | ||
}, | ||
"repository": "[email protected]:edgio-docs/edgio-polyfill.io-replace-example.git" | ||
} | ||
} |
File renamed without changes.
File renamed without changes.