Ignore requests from bot for headless router (#23733)
This commit is contained in:
1 parent
8f82e78597
commit
bb2dcc51c6
3 files changed
+30
No files matched your search
@@ -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") {
|
||||
|
||||
Reference in new issue
Block a user