Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
aaanh committed Oct 24, 2022
1 parent e673789 commit 0ebeb1b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
43 changes: 43 additions & 0 deletions workers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
addEventListener("fetch", (event) => {
event.respondWith(
handleRequest(event.request).catch(
(err) => new Response(err.stack, { status: 500 })
)
);
});

const invalid = `<DOCTYPE html>
<body>
<h1>Invalid Request</h1>
<p>Code: 404</p>
</body>
</html>
`

/**
* Many more examples available at:
* https://developers.cloudflare.com/workers/examples
* @param {Request} request
* @returns {Promise<Response>}
*/
async function handleRequest(request) {
const { searchParams } = new URL(request.url);

let gist_url = searchParams.get('gist_url') ?? null

console.log(gist_url)

if (gist_url == null || gist_url == '') {
return new Response(invalid, {
headers: {
'content-type': 'text/html;charset=UTF-8'
}
})
}
else {
const response = gist_url + '/raw'
return fetch(response);
}


}

0 comments on commit 0ebeb1b

Please sign in to comment.