Last active
January 25, 2021 07:37
-
-
Save sweepies/26cd5006427cfba63b0b3030e638c404 to your computer and use it in GitHub Desktop.
conspire cloudflare shim for discord embeds
This file contains 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 characters
const template = "<html><head><meta property=\"og:image\" content=\"{PATH}\"></head></html>" | |
addEventListener('fetch', event => { | |
let request = event.request | |
let ua = request.headers.get("User-Agent") | |
let path = new URL(request.url).pathname | |
let expr = new RegExp(/.*(png|jpg|jpeg|webp|gif)$/) | |
// test for user agent and image type | |
if (ua !== null && ua.includes("Discord") && expr.test(path)) { | |
const html = template.replace("{PATH}", path) | |
event.respondWith(new Response(html, {status: 200, headers: new Headers({"Content-Type": "text/html"})})) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment