Last active
June 29, 2025 06:50
-
-
Save abersheeran/c251fbd34de24fc1bf0adc60a687e75b to your computer and use it in GitHub Desktop.
Revisions
-
abersheeran revised this gist
Sep 10, 2022 . 1 changed file with 33 additions and 28 deletions.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 @@ -7,41 +7,46 @@ addEventListener("fetch", (event) => { }); async function handleRequest(request) { const url = getUrl(request) console.log(`${request.method} ${url}`) if (!url) { return new Response( Page, { headers: { "Content-Type": "text/html" }, status: 404, } ) } let response = await fetch(new Request(url, { body: request.body, headers: request.headers, method: request.method, redirect: "follow", })) let { readable, writable } = new TransformStream() response.body.pipeTo(writable) return new Response( readable, { headers: response.headers, status: response.status, } ) } const getUrl = (request) => { const { pathname, searchParams } = new URL(request.url) if (pathname.startsWith("/http")) { return pathname.slice(1).replace(/http:\/(?!\/)/, "http://",).replace(/https:\/(?!\/)/, "https://") } const searchParamsUrl = searchParams.get("url"); if (searchParamsUrl?.startsWith("http")) { return searchParamsUrl } } const Page = `<!DOCTYPE html> <html> <head> -
abersheeran revised this gist
Mar 25, 2022 . 1 changed file with 3 additions and 1 deletion.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 @@ -76,10 +76,12 @@ const SearchPage = `<!DOCTYPE html> flex-direction: row; align-items: center; justify-content: center; border: solid 1px #fafafa; box-shadow: 0 0 10px #eee; } input { width: calc(240px + 7vw); height: 40px; border-radius: 0px; border: none; -
abersheeran created this gist
Mar 25, 2022 .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,105 @@ addEventListener("fetch", (event) => { event.respondWith( handleRequest(event.request).catch( (err) => new Response(err.stack, { status: 500 }) ) ); }); async function handleRequest(request) { console.log(`${request.method} ${request.url}`) const sendRequest = async (url) => { let response = await fetch(new Request(url, { body: request.body, headers: request.headers, method: request.method, redirect: "follow", })) let { readable, writable } = new TransformStream() response.body.pipeTo(writable) return new Response(readable, response) } const { pathname, searchParams } = new URL(request.url) if (pathname.startsWith("/http")) { let url = pathname.slice(1).replace("http:/", "http://").replace("https:/", "https://") return await sendRequest(url) } if (searchParams.get("url")?.startsWith("http")) { return await sendRequest(searchParams.get("url")) } return new Response( SearchPage, { headers: { "Content-Type": "text/html" }, status: 404, } ) } const SearchPage = `<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Proxy | Created by aber</title> </head> <body> <form> <div> <input name="url" type="url" /> <button type="submit">→</button> </div> </form> <style> body { background-color: #fafafa; } form { display: flex; flex-direction: column; align-items: center; justify-content: center; margin-top: 100px; } div { display: flex; flex-direction: row; align-items: center; justify-content: center; } input { width: 300px; height: 40px; border-radius: 0px; border: none; outline: none; padding: 0 10px; flex: 1; } button { width: 50px; height: 40px; border-radius: 0px; border: none; background-color: #fff; color: #000; font-size: 16px; cursor: pointer; } </style> </body> </html> `