Created
June 24, 2024 04:05
-
-
Save SlashNephy/2a3032940ed9d71844b96d52f567c0d2 to your computer and use it in GitHub Desktop.
すべてのクローラーをブロックする robots.txt を配信する Cloudflare Worker
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 CONTENT = ` | |
User-agent: * | |
Disallow: / | |
`.trim() | |
export default { | |
async fetch(request) { | |
const url = new URL(request.url); | |
if (url.pathname.endsWith('/robots.txt')) { | |
return new Response(CONTENT, { | |
headers: { | |
'Content-Type': 'text/plain', | |
} | |
}) | |
} | |
const response = await fetch(request); | |
const newHeaders = new Headers(response.headers); | |
newHeaders.set('X-Robots-Tag', 'none'); | |
return new Response(response.body, { | |
status: response.status, | |
statusText: response.statusText, | |
headers: newHeaders, | |
}) | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment