From 71dd26bbcd7a58e86bdcdf3839c389b48613e9ce Mon Sep 17 00:00:00 2001 From: Gregory Boch Date: Tue, 1 Dec 2026 21:24:23 +0900 Subject: [PATCH] feat(claim-db-worker): add robots.txt and noindex the /web pages Opening a /web page creates a temporary database right away, and /api only answers the app's own requests, so neither is meant for crawlers. - app/robots.ts serves /robots.txt (a 404 until now): User-Agent *, Allow /, Disallow /web/ and /api/. - /web pages send from a small server layout. The existing client layout moved byte for byte to app/web/WebLayoutClient.tsx. - Not changed: the landing page, and what /web does for people. Co-Authored-By: Claude Opus 5.5 --- apps/claim-db-worker/app/robots.ts | 14 + .../app/web/WebLayoutClient.tsx | 292 +++++++++++++++++ apps/claim-db-worker/app/web/layout.tsx | 300 +----------------- 3 files changed, 318 insertions(+), 288 deletions(-) create mode 100644 apps/claim-db-worker/app/robots.ts create mode 100644 apps/claim-db-worker/app/web/WebLayoutClient.tsx diff --git a/apps/claim-db-worker/app/robots.ts b/apps/claim-db-worker/app/robots.ts new file mode 100644 index 0000000..4a6cd9d --- /dev/null +++ b/apps/claim-db-worker/app/robots.ts @@ -0,0 +1,14 @@ +import type { MetadataRoute } from "next"; + +// Served as /robots.txt. Pages under /web/ create a temporary database when +// they open, and /api/ only answers the app's own requests, so both prefixes +// are disallowed. The bare /web path gets noindex from app/web/layout.tsx. +export default function robots(): MetadataRoute.Robots { + return { + rules: { + userAgent: "*", + allow: "/", + disallow: ["/web/", "/api/"], + }, + }; +} diff --git a/apps/claim-db-worker/app/web/WebLayoutClient.tsx b/apps/claim-db-worker/app/web/WebLayoutClient.tsx new file mode 100644 index 0000000..a987076 --- /dev/null +++ b/apps/claim-db-worker/app/web/WebLayoutClient.tsx @@ -0,0 +1,292 @@ +"use client"; + +import React, { useState, useEffect, Suspense } from "react"; +import { useRouter, usePathname } from "next/navigation"; +import { useDropContext } from "../contexts/DropContext"; +import { customToast } from "@/lib/custom-toast"; +import Modal from "@/components/Modal"; +import { Database, Code, Eye, PlusCircle, Copy } from "lucide-react"; +import LoadingScreen from "@/components/LoadingScreen"; +import { LoadingMark, Mascot } from "@/components/brand/Brand"; +import { PrismButton, PrismButtonOutline } from "@/components/brand/PrismButton"; +import { DatabaseProvider, useDatabase } from "./DatabaseContext"; + +interface WebLayoutProps { + children: React.ReactNode; +} + +const WebLayoutContent = ({ children }: WebLayoutProps) => { + const [showNewDbConfirm, setShowNewDbConfirm] = useState(false); + const { dbInfo, loading, clearDatabase } = useDatabase(); + const { + setTimeRemaining, + setProjectId, + handleClaimDatabase, + timeRemaining, + } = useDropContext(); + const router = useRouter(); + const pathname = usePathname(); + + const currentTab = pathname.split("/").pop() || "connect"; + + useEffect(() => { + if (dbInfo.projectId) { + setProjectId(dbInfo.projectId); + } + }, [dbInfo.projectId, setProjectId]); + + useEffect(() => { + if (!loading && dbInfo.expirationTime) { + const calculateTimeRemaining = () => { + const now = Date.now(); + const timeRemainingMs = dbInfo.expirationTime! - now; + if (timeRemainingMs <= 0) { + setTimeRemaining(0); + clearDatabase(); + return; + } + + setTimeRemaining(Math.floor(timeRemainingMs / 1000)); + }; + + calculateTimeRemaining(); + const timer = setInterval(calculateTimeRemaining, 1000); + return () => clearInterval(timer); + } + }, [loading, dbInfo.expirationTime, setTimeRemaining, clearDatabase]); + + const handleCreateNewDatabase = () => { + setShowNewDbConfirm(true); + }; + + const confirmCreateNewDatabase = () => { + clearDatabase(); + window.location.reload(); + }; + + const handleTabChange = (tab: string) => { + router.push(`/web/${tab}`); + }; + + if (!loading && (timeRemaining === 0 || timeRemaining === null)) { + return ( +
+
+ +

+ Your temporary database has expired or has been claimed. Please create a new one. +

+
+ Create new database +
+
+
+ ); + } + + return ( + <> +
+
+
+
+
+ + Claim database + + + +
+ +
+
+
+ + + +
+ +
+ + +
+
+
+
+ + {loading ? ( +
+ +
+ ) : ( +
+ {children} +
+ )} +
+
+
+ + setShowNewDbConfirm(false)} + title="Create New Database?" + > +

+ This will delete your current database and create a new one. Your + current connection strings and data will be lost. +

+
+ setShowNewDbConfirm(false)}> + Cancel + + + Create new database + +
+
+ + ); +}; + +interface TabHeaderProps { + activeTab: string; + onTabChange: (tab: string) => void; + tabName: string; + buttonText: string; + icon: string; + buttonTextMobile: string; +} + +const TabHeader = ({ + activeTab, + onTabChange, + tabName, + buttonText, + icon, + buttonTextMobile, +}: TabHeaderProps) => { + const isActive = activeTab === tabName; + + const getIcon = () => { + switch (icon) { + case "database": + return ; + case "code": + return ; + case "eye": + return ; + default: + return ; + } + }; + + return ( + + ); +}; + +const WebLayout = ({ children }: WebLayoutProps) => { + return ( + + +
+ +
+ + } + > + {children} +
+
+ ); +}; + +export default WebLayout; diff --git a/apps/claim-db-worker/app/web/layout.tsx b/apps/claim-db-worker/app/web/layout.tsx index a987076..b7bb919 100644 --- a/apps/claim-db-worker/app/web/layout.tsx +++ b/apps/claim-db-worker/app/web/layout.tsx @@ -1,292 +1,16 @@ -"use client"; +import type { Metadata } from "next"; +import WebLayout from "./WebLayoutClient"; -import React, { useState, useEffect, Suspense } from "react"; -import { useRouter, usePathname } from "next/navigation"; -import { useDropContext } from "../contexts/DropContext"; -import { customToast } from "@/lib/custom-toast"; -import Modal from "@/components/Modal"; -import { Database, Code, Eye, PlusCircle, Copy } from "lucide-react"; -import LoadingScreen from "@/components/LoadingScreen"; -import { LoadingMark, Mascot } from "@/components/brand/Brand"; -import { PrismButton, PrismButtonOutline } from "@/components/brand/PrismButton"; -import { DatabaseProvider, useDatabase } from "./DatabaseContext"; - -interface WebLayoutProps { - children: React.ReactNode; -} - -const WebLayoutContent = ({ children }: WebLayoutProps) => { - const [showNewDbConfirm, setShowNewDbConfirm] = useState(false); - const { dbInfo, loading, clearDatabase } = useDatabase(); - const { - setTimeRemaining, - setProjectId, - handleClaimDatabase, - timeRemaining, - } = useDropContext(); - const router = useRouter(); - const pathname = usePathname(); - - const currentTab = pathname.split("/").pop() || "connect"; - - useEffect(() => { - if (dbInfo.projectId) { - setProjectId(dbInfo.projectId); - } - }, [dbInfo.projectId, setProjectId]); - - useEffect(() => { - if (!loading && dbInfo.expirationTime) { - const calculateTimeRemaining = () => { - const now = Date.now(); - const timeRemainingMs = dbInfo.expirationTime! - now; - if (timeRemainingMs <= 0) { - setTimeRemaining(0); - clearDatabase(); - return; - } - - setTimeRemaining(Math.floor(timeRemainingMs / 1000)); - }; - - calculateTimeRemaining(); - const timer = setInterval(calculateTimeRemaining, 1000); - return () => clearInterval(timer); - } - }, [loading, dbInfo.expirationTime, setTimeRemaining, clearDatabase]); - - const handleCreateNewDatabase = () => { - setShowNewDbConfirm(true); - }; - - const confirmCreateNewDatabase = () => { - clearDatabase(); - window.location.reload(); - }; - - const handleTabChange = (tab: string) => { - router.push(`/web/${tab}`); - }; - - if (!loading && (timeRemaining === 0 || timeRemaining === null)) { - return ( -
-
- -

- Your temporary database has expired or has been claimed. Please create a new one. -

-
- Create new database -
-
-
- ); - } - - return ( - <> -
-
-
-
-
- - Claim database - - - -
- -
-
-
- - - -
- -
- - -
-
-
-
- - {loading ? ( -
- -
- ) : ( -
- {children} -
- )} -
-
-
- - setShowNewDbConfirm(false)} - title="Create New Database?" - > -

- This will delete your current database and create a new one. Your - current connection strings and data will be lost. -

-
- setShowNewDbConfirm(false)}> - Cancel - - - Create new database - -
-
- - ); +// Opening a /web page creates a temporary database for the visitor, so these +// pages stay out of search results. app/robots.ts also disallows /web/. +export const metadata: Metadata = { + robots: { index: false }, }; -interface TabHeaderProps { - activeTab: string; - onTabChange: (tab: string) => void; - tabName: string; - buttonText: string; - icon: string; - buttonTextMobile: string; +export default function Layout({ + children, +}: Readonly<{ + children: React.ReactNode; +}>) { + return {children}; } - -const TabHeader = ({ - activeTab, - onTabChange, - tabName, - buttonText, - icon, - buttonTextMobile, -}: TabHeaderProps) => { - const isActive = activeTab === tabName; - - const getIcon = () => { - switch (icon) { - case "database": - return ; - case "code": - return ; - case "eye": - return ; - default: - return ; - } - }; - - return ( - - ); -}; - -const WebLayout = ({ children }: WebLayoutProps) => { - return ( - - -
- -
- - } - > - {children} -
-
- ); -}; - -export default WebLayout;