Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ee/ui-component/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function YourApp() {
| Prop | Type | Default | Description |
| --------------- | ----------------------- | ------------------------- | -------------------------------------- |
| `connectionUri` | `string` | `undefined` | Connection URI for Morphik API |
| `apiBaseUrl` | `string` | `"http://localhost:8000"` | Base URL for API requests |
| `apiBaseUrl` | `string` | `"http://{hostname}:8000"` | Base URL for API requests (defaults to current hostname) |
| `isReadOnlyUri` | `boolean` | `false` | Controls whether the URI can be edited |
| `onUriChange` | `(uri: string) => void` | `undefined` | Callback when URI is changed |

Expand Down
4 changes: 3 additions & 1 deletion ee/ui-component/components/MorphikUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import { useRouter, usePathname } from "next/navigation";
const MorphikUI: React.FC<MorphikUIProps> = props => {
const {
connectionUri,
apiBaseUrl = "http://localhost:8000",
apiBaseUrl = typeof window !== 'undefined'
? `${window.location.protocol}//${window.location.hostname}:8000`
: "http://localhost:8000",
initialSection = "documents",
initialFolder = null,
onBackClick,
Expand Down
8 changes: 6 additions & 2 deletions ee/ui-component/components/pdf/PDFViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ export function PDFViewer({ apiBaseUrl, authToken, initialDocumentId, onChatTogg

// Use the new PDF chat sessions hook
const { currentChatId, createNewSession } = usePDFChatSessions({
apiBaseUrl: apiBaseUrl || process.env.NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000",
apiBaseUrl: apiBaseUrl || process.env.NEXT_PUBLIC_API_BASE_URL || (typeof window !== 'undefined'
? `${window.location.protocol}//${window.location.hostname}:8000`
: "http://localhost:8000"),
authToken: authToken || null,
documentName: pdfState.documentId || pdfState.documentName || pdfState.file?.name,
});
Expand Down Expand Up @@ -304,7 +306,9 @@ export function PDFViewer({ apiBaseUrl, authToken, initialDocumentId, onChatTogg

// Make API call to our document chat endpoint
const response = await fetch(
`${apiBaseUrl || process.env.NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000"}/document/chat/${chatId}/complete`,
`${apiBaseUrl || process.env.NEXT_PUBLIC_API_BASE_URL || (typeof window !== 'undefined'
? `${window.location.protocol}//${window.location.hostname}:8000`
: "http://localhost:8000")}/document/chat/${chatId}/complete`,
{
method: "POST",
headers: {
Expand Down
4 changes: 3 additions & 1 deletion ee/ui-component/contexts/morphik-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import React, { createContext, useContext, useState } from "react";
import { extractTokenFromUri, getApiBaseUrlFromUri } from "@/lib/utils";

const DEFAULT_API_BASE_URL = "http://localhost:8000";
const DEFAULT_API_BASE_URL = typeof window !== 'undefined'
? `${window.location.protocol}//${window.location.hostname}:8000`
: "http://localhost:8000";

interface MorphikContextType {
connectionUri: string | null;
Expand Down
4 changes: 3 additions & 1 deletion ee/ui-component/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export function extractTokenFromUri(uri: string | undefined): string | null {
* @param defaultUrl - The default API URL to use if URI is invalid
* @returns The API base URL derived from the URI host
*/
export function getApiBaseUrlFromUri(uri: string | undefined, defaultUrl: string = "http://localhost:8000"): string {
export function getApiBaseUrlFromUri(uri: string | undefined, defaultUrl: string = typeof window !== 'undefined'
? `${window.location.protocol}//${window.location.hostname}:8000`
: "http://localhost:8000"): string {
// If URI is empty or undefined, connect to the default URL
if (!uri || uri.trim() === "") {
return defaultUrl;
Expand Down