fix: Exclude Twitter/Slack bots from root page redirects (#1318)

This commit is contained in:
Kamil Ogórek
2023-06-17 19:13:04 +02:00
committed by GitHub
parent 2b11803528
commit 219ab574db
+9 -1
View File
@@ -11,10 +11,18 @@ import Projects from "../components/Projects.tsx";
import projects from "../data/showcase.json" assert { type: "json" };
import Header from "../components/Header.tsx";
function isOpenGraphUA(header: string | null): boolean {
if (!header) {
return false;
}
return header.startsWith("Twitterbot") || header.startsWith("Slackbot");
}
export const handler: Handlers = {
GET(req, ctx) {
const accept = req.headers.get("accept");
if (accept && !accept.includes("text/html")) {
const userAgent = req.headers.get("user-agent");
if (!accept?.includes("text/html") && !isOpenGraphUA(userAgent)) {
const path = `https://deno.land/x/fresh@${VERSIONS[0]}/init.ts`;
return new Response(`Redirecting to ${path}`, {
headers: { "Location": path },