diff --git a/components/app-sidebar.tsx b/components/app-sidebar.tsx index ff9c2f0..30d058b 100644 --- a/components/app-sidebar.tsx +++ b/components/app-sidebar.tsx @@ -41,7 +41,7 @@ export function AppSidebar({ user }: { user: User | undefined }) { const [showDeleteAllDialog, setShowDeleteAllDialog] = useState(false); const handleDeleteAll = () => { - const deletePromise = fetch("/api/history", { + const deletePromise = fetch(`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/history`, { method: "DELETE", }); diff --git a/components/artifact.tsx b/components/artifact.tsx index 5cde3b1..5a64d90 100644 --- a/components/artifact.tsx +++ b/components/artifact.tsx @@ -149,7 +149,7 @@ function PureArtifact({ } if (currentDocument.content !== updatedContent) { - await fetch(`/api/document?id=${artifact.documentId}`, { + await fetch(`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/document?id=${artifact.documentId}`, { method: "POST", body: JSON.stringify({ title: artifact.title, diff --git a/components/chat.tsx b/components/chat.tsx index 9264246..bc96f26 100644 --- a/components/chat.tsx +++ b/components/chat.tsx @@ -103,7 +103,7 @@ export function Chat({ return shouldContinue; }, transport: new DefaultChatTransport({ - api: "/api/chat", + api: `${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/chat`, fetch: fetchWithErrorHandlers, prepareSendMessagesRequest(request) { const lastMessage = request.messages.at(-1); @@ -166,12 +166,12 @@ export function Chat({ }); setHasAppendedQuery(true); - window.history.replaceState({}, "", `/chat/${id}`); + window.history.replaceState({}, "", `${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/chat/${id}`); } }, [query, sendMessage, hasAppendedQuery, id]); const { data: votes } = useSWR( - messages.length >= 2 ? `/api/vote?chatId=${id}` : null, + messages.length >= 2 ? `${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/vote?chatId=${id}` : null, fetcher ); @@ -268,7 +268,7 @@ export function Chat({ "https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%3Fmodal%3Dadd-credit-card", "_blank" ); - window.location.href = "/"; + window.location.href = `${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/`; }} > Activate diff --git a/components/message-actions.tsx b/components/message-actions.tsx index a925e5f..ff5d8a9 100644 --- a/components/message-actions.tsx +++ b/components/message-actions.tsx @@ -77,7 +77,7 @@ export function PureMessageActions({ data-testid="message-upvote" disabled={vote?.isUpvoted} onClick={() => { - const upvote = fetch("/api/vote", { + const upvote = fetch(`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/vote`, { method: "PATCH", body: JSON.stringify({ chatId, @@ -90,7 +90,7 @@ export function PureMessageActions({ loading: "Upvoting Response...", success: () => { mutate( - `/api/vote?chatId=${chatId}`, + `${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/vote?chatId=${chatId}`, (currentVotes) => { if (!currentVotes) { return []; @@ -126,7 +126,7 @@ export function PureMessageActions({ data-testid="message-downvote" disabled={vote && !vote.isUpvoted} onClick={() => { - const downvote = fetch("/api/vote", { + const downvote = fetch(`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/vote`, { method: "PATCH", body: JSON.stringify({ chatId, @@ -139,7 +139,7 @@ export function PureMessageActions({ loading: "Downvoting Response...", success: () => { mutate( - `/api/vote?chatId=${chatId}`, + `${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/vote?chatId=${chatId}`, (currentVotes) => { if (!currentVotes) { return []; diff --git a/components/multimodal-input.tsx b/components/multimodal-input.tsx index ed62df1..2977957 100644 --- a/components/multimodal-input.tsx +++ b/components/multimodal-input.tsx @@ -145,7 +145,7 @@ function PureMultimodalInput({ const [uploadQueue, setUploadQueue] = useState([]); const submitForm = useCallback(() => { - window.history.pushState({}, "", `/chat/${chatId}`); + window.history.pushState({}, "", `${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/chat/${chatId}`); sendMessage({ role: "user", @@ -188,7 +188,7 @@ function PureMultimodalInput({ formData.append("file", file); try { - const response = await fetch("/api/files/upload", { + const response = await fetch(`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/files/upload`, { method: "POST", body: formData, }); diff --git a/components/sidebar-history.tsx b/components/sidebar-history.tsx index 9ac1ab5..80c79a8 100644 --- a/components/sidebar-history.tsx +++ b/components/sidebar-history.tsx @@ -85,7 +85,7 @@ export function getChatHistoryPaginationKey( } if (pageIndex === 0) { - return `/api/history?limit=${PAGE_SIZE}`; + return `${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/history?limit=${PAGE_SIZE}`; } const firstChatFromPage = previousPageData.chats.at(-1); @@ -94,7 +94,7 @@ export function getChatHistoryPaginationKey( return null; } - return `/api/history?ending_before=${firstChatFromPage.id}&limit=${PAGE_SIZE}`; + return `${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/history?ending_before=${firstChatFromPage.id}&limit=${PAGE_SIZE}`; } export function SidebarHistory({ user }: { user: User | undefined }) { @@ -130,7 +130,7 @@ export function SidebarHistory({ user }: { user: User | undefined }) { setShowDeleteDialog(false); - const deletePromise = fetch(`/api/chat?id=${chatToDelete}`, { + const deletePromise = fetch(`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/chat?id=${chatToDelete}`, { method: "DELETE", }); diff --git a/components/suggested-actions.tsx b/components/suggested-actions.tsx index 8f63336..a278a2c 100644 --- a/components/suggested-actions.tsx +++ b/components/suggested-actions.tsx @@ -37,7 +37,7 @@ function PureSuggestedActions({ chatId, sendMessage }: SuggestedActionsProps) { { - window.history.pushState({}, "", `/chat/${chatId}`); + window.history.pushState({}, "", `${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/chat/${chatId}`); sendMessage({ role: "user", parts: [{ type: "text", text: suggestion }], diff --git a/hooks/use-chat-visibility.ts b/hooks/use-chat-visibility.ts index d0f8945..d9d141f 100644 --- a/hooks/use-chat-visibility.ts +++ b/hooks/use-chat-visibility.ts @@ -18,7 +18,7 @@ export function useChatVisibility({ initialVisibilityType: VisibilityType; }) { const { mutate, cache } = useSWRConfig(); - const history: ChatHistory = cache.get("/api/history")?.data; + const history: ChatHistory = cache.get(`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/history`)?.data; const { data: localVisibility, mutate: setLocalVisibility } = useSWR( `${chatId}-visibility`, diff --git a/next.config.ts b/next.config.ts index 33635e9..d9cbe45 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,8 +1,13 @@ import type { NextConfig } from "next"; +const basePath = "/demo"; + const nextConfig: NextConfig = { - basePath: "/demo", + basePath, assetPrefix: "/demo-assets", + env: { + NEXT_PUBLIC_BASE_PATH: basePath, + }, cacheComponents: true, images: { remotePatterns: [