Created
September 26, 2024 05:23
-
-
Save jb510/b898c75df7879c38ba052d97cc9a04ff to your computer and use it in GitHub Desktop.
Revisions
-
jb510 created this gist
Sep 26, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ async function handleRequest(request) { const url = new URL(request.url); // Modify the URL to target WordPress.org if (url.pathname.startsWith('/plugins/')) { url.hostname = 'api.wordpress.org'; url.pathname = url.pathname.replace('/plugins/', '/plugins/info/1.2/'); } else if (url.pathname.startsWith('/themes/')) { url.hostname = 'api.wordpress.org'; url.pathname = url.pathname.replace('/themes/', '/themes/info/1.2/'); } else { return new Response('Invalid Request', { status: 400 }); } // Fetch the request from the WordPress API const response = await fetch(url.toString(), { method: request.method, headers: request.headers, }); return response; } addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)); });