Skip to content

Instantly share code, notes, and snippets.

@jogerj
Last active September 11, 2025 21:45
Show Gist options
  • Save jogerj/09723ba9f82d4194512244bd916c941f to your computer and use it in GitHub Desktop.
Save jogerj/09723ba9f82d4194512244bd916c941f to your computer and use it in GitHub Desktop.
Cloudflare Worker for redirecting autodiscovery/autoconfiguration of email servers
/**
* Handle redirects with cloudflare worker to avoid duplication
* https://forum.sympl.io/t/configure-auto-discover-for-mail-setup/94/6
*/
export default {
async fetch(request) {
const url = new URL(request.url);
if (url.pathname === "/.well-known/autoconfig/mail/config-v1.1.xml") {
const targetUrl = `https://autoconfig.${url.hostname}/mail/config-v1.1.xml`;
return fetch(targetUrl, request);
}
if (url.pathname === "/autodiscover/autodiscover.xml") {
const targetUrl = `https://autodiscover.${url.hostname}/autodiscover/autodiscover.xml`
return fetch(targetUrl, request)
}
return fetch(request);
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment