cloudflare-worker.js raw

   1  // moxielang.dev as a Cloudflare Worker: the same two answers as the Caddyfile in
   2  // this directory, for a domain whose DNS is on Cloudflare. Route it as
   3  // `moxielang.dev/*` (and `www.moxielang.dev/*` if that name exists).
   4  const REPO = "https://github.com/moxie-language/toolchain";
   5  const GO_IMPORT = "moxielang.dev git https://github.com/moxie-language/toolchain.git";
   6  
   7  const PAGE = `<!DOCTYPE html>
   8  <html lang="en"><head><meta charset="utf-8">
   9  <meta name="go-import" content="${GO_IMPORT}">
  10  <meta http-equiv="refresh" content="0; url=${REPO}">
  11  <title>moxielang.dev - the Moxie toolchain</title></head>
  12  <body><h1>moxielang.dev</h1>
  13  <p>The Moxie toolchain lives at <a href="${REPO}">github.com/moxie-language/toolchain</a>.</p>
  14  <script>location.replace("${REPO}");</script>
  15  </body></html>`;
  16  
  17  export default {
  18    fetch(request) {
  19      const url = new URL(request.url);
  20      if (url.searchParams.get("go-get") === "1") {
  21        return new Response(PAGE, {
  22          headers: {
  23            "content-type": "text/html; charset=utf-8",
  24            "cache-control": "public, max-age=300",
  25          },
  26        });
  27      }
  28      return Response.redirect(REPO, 301);
  29    },
  30  };
  31