From 547d38240a2ea0ba25b0de9bdf3ac0ff2bf9d789 Mon Sep 17 00:00:00 2001 From: johnd0e <1838643+johnd0e@users.noreply.github.com> Date: Thu, 7 Mar 2024 02:24:28 +0100 Subject: [PATCH] Implement /token page GitHub Copilot Token Generator robots: https://developers.google.com/search/docs/crawling-indexing/block-indexing Memo just in case: there were more alternative static serving possibilities: - https://developers.cloudflare.com/workers/configuration/sites/start-from-worker/ - wrangler deploy --assets ./public --- src/get_copilot_token.html | 120 +++++++++++++++++++++++++++++++++++++ src/worker.mjs | 13 ++++ wrangler.toml | 1 - 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 src/get_copilot_token.html diff --git a/src/get_copilot_token.html b/src/get_copilot_token.html new file mode 100644 index 0000000..e112820 --- /dev/null +++ b/src/get_copilot_token.html @@ -0,0 +1,120 @@ + + + + + + + + + +

GitHub Copilot token Generator

+

Loading... +

+ + + diff --git a/src/worker.mjs b/src/worker.mjs index c1418a0..2cccd2f 100644 --- a/src/worker.mjs +++ b/src/worker.mjs @@ -1,3 +1,5 @@ +import token_html from "./get_copilot_token.html"; + export default { async fetch (request, env) { if (request.method === "OPTIONS") { @@ -7,6 +9,17 @@ export default { if (url.pathname === "/v1/models") { return handleModels(request); } + if (url.pathname === "/token") { + return new Response(token_html, { + headers: { "Content-Type": "text/html" } + }); + } + if (url.pathname === "/corsproxy" && url.search.startsWith("?https://")) { + let resp = await fetch(url.search.substring(1), request); + resp = new Response(resp.body, resp); + resp.headers.set("Access-Control-Allow-Origin", "*"); + return resp; + } const auth = request.headers.get("Authorization"); let authKey = auth && auth.split(" ")[1]; if (!authKey) { diff --git a/wrangler.toml b/wrangler.toml index 960a85f..c2d7580 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -1,7 +1,6 @@ name = "copilot" main = "src/worker.mjs" compatibility_date = "2024-01-17" -no_bundle = true [[kv_namespaces]] binding = "KV"