From 4694f961f23ff8c9e99706f52611e5a03065e6a0 Mon Sep 17 00:00:00 2001 From: Sanny Nguyen Hung Date: Fri, 5 Jan 2024 09:31:06 +0100 Subject: [PATCH] feat(preview): add robots route --- app/routes/robots[.]txt.tsx | 24 ++++++++++++++++++++++++ public/robots.txt | 2 -- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 app/routes/robots[.]txt.tsx delete mode 100644 public/robots.txt diff --git a/app/routes/robots[.]txt.tsx b/app/routes/robots[.]txt.tsx new file mode 100644 index 000000000..dc24306de --- /dev/null +++ b/app/routes/robots[.]txt.tsx @@ -0,0 +1,24 @@ +import { LoaderFunctionArgs } from "@remix-run/node"; +import { config } from "~/services/env/env.server"; + +export const loader = () => { + // Initial robot content is to disallow all + let robotContent = ` + User-agent: * + Disallow: / + `; + + if (config().ENVIRONMENT === "production") { + robotContent = ` + User-agent: * + Disallow: /storybook + `; + } + + return new Response(robotContent, { + status: 200, + headers: { + "Content-Type": "text/plain", + }, + }); +}; diff --git a/public/robots.txt b/public/robots.txt deleted file mode 100644 index 5e191c471..000000000 --- a/public/robots.txt +++ /dev/null @@ -1,2 +0,0 @@ -User-agent: * -Disallow: /storybook \ No newline at end of file