Skip to content

Instantly share code, notes, and snippets.

@sweepies
Last active January 25, 2021 07:37
Show Gist options
  • Save sweepies/26cd5006427cfba63b0b3030e638c404 to your computer and use it in GitHub Desktop.
Save sweepies/26cd5006427cfba63b0b3030e638c404 to your computer and use it in GitHub Desktop.
conspire cloudflare shim for discord embeds
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