Ignore requests from bot for headless router (#23733)

This commit is contained in:
Hariom Balhara authored and GitHub committed 2025-09-10 16:59:04 +05:30
1 parent 8f82e78597
commit bb2dcc51c6
3 files changed
+30

No files matched your search

+1
View File
@@ -93,6 +93,7 @@
"handlebars": "^4.7.7",
"ical.js": "^1.4.0",
"ics": "^2.37.0",
"isbot": "^5.1.30",
"jose": "^4.13.1",
"jotai": "^2.12.2",
"jsdom": "^22.0.0",
@@ -1,14 +1,35 @@
import { wrapGetServerSidePropsWithSentry } from "@sentry/nextjs";
import { isbot } from "isbot";
import type { GetServerSidePropsContext } from "next";
import { getRoutedUrl, hasEmbedPath } from "@calcom/features/routing-forms/lib/getRoutedUrl";
import logger from "@calcom/lib/logger";
import { TRPCError } from "@trpc/server";
const log = logger.getSubLogger({ prefix: ["router/getServerSideProps"] });
// Show a positive message to the bots so that they don't think that the form is broken.
const BOT_MESSAGE = "Thank you for your interest! We will be in touch soon.";
export const getServerSideProps = wrapGetServerSidePropsWithSentry(async function getServerSideProps(
context: GetServerSidePropsContext
) {
try {
// Check if the request is from a bot
const userAgent = context.req.headers["user-agent"];
if (userAgent && isbot(userAgent)) {
log.info(`[BOT] Ignoring request from user agent: ${userAgent}`);
return {
props: {
isEmbed: hasEmbedPath(context.req.url || ""),
form: null,
message: BOT_MESSAGE,
errorMessage: null,
},
};
}
return await getRoutedUrl(context);
} catch (error) {
if (error instanceof TRPCError && error.code === "TOO_MANY_REQUESTS") {