mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-27 19:25:15 +02:00
refactor(env): replace inline process.env reads with BACKEND_URL in editor, chat, dashboard and settings
This commit is contained in:
parent
8174949b38
commit
fead3a64f4
10 changed files with 33 additions and 27 deletions
|
|
@ -5,6 +5,7 @@ import { Logo } from "@/components/Logo";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { trackLoginAttempt } from "@/lib/posthog/events";
|
import { trackLoginAttempt } from "@/lib/posthog/events";
|
||||||
import { AmbientBackground } from "./AmbientBackground";
|
import { AmbientBackground } from "./AmbientBackground";
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
function GoogleGLogo({ className }: { className?: string }) {
|
function GoogleGLogo({ className }: { className?: string }) {
|
||||||
return (
|
return (
|
||||||
|
|
@ -34,6 +35,9 @@ function GoogleGLogo({ className }: { className?: string }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=======
|
||||||
|
import { BACKEND_URL } from "@/lib/env-config";
|
||||||
|
>>>>>>> 1127aedb4 (refactor(env): replace inline process.env reads with BACKEND_URL in editor, chat, dashboard and settings)
|
||||||
export function GoogleLoginButton() {
|
export function GoogleLoginButton() {
|
||||||
const t = useTranslations("auth");
|
const t = useTranslations("auth");
|
||||||
const [isRedirecting, setIsRedirecting] = useState(false);
|
const [isRedirecting, setIsRedirecting] = useState(false);
|
||||||
|
|
@ -50,7 +54,7 @@ export function GoogleLoginButton() {
|
||||||
// cross-origin fetch requests may not be sent on subsequent redirects.
|
// cross-origin fetch requests may not be sent on subsequent redirects.
|
||||||
// The authorize-redirect endpoint does a server-side redirect to Google
|
// The authorize-redirect endpoint does a server-side redirect to Google
|
||||||
// and sets the CSRF cookie properly for same-site context.
|
// and sets the CSRF cookie properly for same-site context.
|
||||||
window.location.href = `${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/auth/google/authorize-redirect`;
|
window.location.href = `${BACKEND_URL}/auth/google/authorize-redirect`;
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div className="relative w-full overflow-hidden">
|
<div className="relative w-full overflow-hidden">
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,9 @@ import { NextResponse } from "next/server";
|
||||||
import type { Context } from "@/types/zero";
|
import type { Context } from "@/types/zero";
|
||||||
import { queries } from "@/zero/queries";
|
import { queries } from "@/zero/queries";
|
||||||
import { schema } from "@/zero/schema";
|
import { schema } from "@/zero/schema";
|
||||||
|
import { BACKEND_URL } from "@/lib/env-config";
|
||||||
|
|
||||||
const backendURL =
|
const backendURL = BACKEND_URL;
|
||||||
process.env.FASTAPI_BACKEND_INTERNAL_URL ||
|
|
||||||
process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL ||
|
|
||||||
"http://localhost:8000";
|
|
||||||
|
|
||||||
async function authenticateRequest(
|
async function authenticateRequest(
|
||||||
request: Request
|
request: Request
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ import {
|
||||||
trackChatResponseReceived,
|
trackChatResponseReceived,
|
||||||
} from "@/lib/posthog/events";
|
} from "@/lib/posthog/events";
|
||||||
import Loading from "../loading";
|
import Loading from "../loading";
|
||||||
|
import { BACKEND_URL } from "@/lib/env-config";
|
||||||
const MobileEditorPanel = dynamic(
|
const MobileEditorPanel = dynamic(
|
||||||
() =>
|
() =>
|
||||||
import("@/components/editor-panel/editor-panel").then((m) => ({
|
import("@/components/editor-panel/editor-panel").then((m) => ({
|
||||||
|
|
@ -777,7 +777,7 @@ export default function NewChatPage() {
|
||||||
if (threadId) {
|
if (threadId) {
|
||||||
const token = getBearerToken();
|
const token = getBearerToken();
|
||||||
if (token) {
|
if (token) {
|
||||||
const backendUrl = process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL || "http://localhost:8000";
|
const backendUrl = BACKEND_URL;
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${backendUrl}/api/v1/threads/${threadId}/cancel-active-turn`,
|
`${backendUrl}/api/v1/threads/${threadId}/cancel-active-turn`,
|
||||||
|
|
@ -978,7 +978,7 @@ export default function NewChatPage() {
|
||||||
let streamBatcher: FrameBatchedUpdater | null = null;
|
let streamBatcher: FrameBatchedUpdater | null = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const backendUrl = process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL || "http://localhost:8000";
|
const backendUrl = BACKEND_URL;
|
||||||
const selection = await getAgentFilesystemSelection(searchSpaceId, {
|
const selection = await getAgentFilesystemSelection(searchSpaceId, {
|
||||||
localFilesystemEnabled,
|
localFilesystemEnabled,
|
||||||
});
|
});
|
||||||
|
|
@ -1520,7 +1520,7 @@ export default function NewChatPage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const backendUrl = process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL || "http://localhost:8000";
|
const backendUrl = BACKEND_URL;
|
||||||
const selection = await getAgentFilesystemSelection(searchSpaceId, {
|
const selection = await getAgentFilesystemSelection(searchSpaceId, {
|
||||||
localFilesystemEnabled,
|
localFilesystemEnabled,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import { useMediaQuery } from "@/hooks/use-media-query";
|
||||||
import { useElectronAPI } from "@/hooks/use-platform";
|
import { useElectronAPI } from "@/hooks/use-platform";
|
||||||
import { authenticatedFetch, getBearerToken, redirectToLogin } from "@/lib/auth-utils";
|
import { authenticatedFetch, getBearerToken, redirectToLogin } from "@/lib/auth-utils";
|
||||||
import { inferMonacoLanguageFromPath } from "@/lib/editor-language";
|
import { inferMonacoLanguageFromPath } from "@/lib/editor-language";
|
||||||
|
import { BACKEND_URL } from "@/lib/env-config";
|
||||||
const PlateEditor = dynamic(
|
const PlateEditor = dynamic(
|
||||||
() => import("@/components/editor/plate-editor").then((m) => ({ default: m.PlateEditor })),
|
() => import("@/components/editor/plate-editor").then((m) => ({ default: m.PlateEditor })),
|
||||||
{ ssr: false, loading: () => <EditorPanelSkeleton /> }
|
{ ssr: false, loading: () => <EditorPanelSkeleton /> }
|
||||||
|
|
@ -209,7 +209,7 @@ export function EditorPanelContent({
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = new URL(
|
const url = new URL(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/documents/${documentId}/editor-content`
|
`${BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/documents/${documentId}/editor-content`
|
||||||
);
|
);
|
||||||
url.searchParams.set("max_length", String(LARGE_DOCUMENT_THRESHOLD));
|
url.searchParams.set("max_length", String(LARGE_DOCUMENT_THRESHOLD));
|
||||||
|
|
||||||
|
|
@ -326,7 +326,7 @@ export function EditorPanelContent({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await authenticatedFetch(
|
const response = await authenticatedFetch(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/documents/${documentId}/save`,
|
`${BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/documents/${documentId}/save`,
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
|
@ -396,7 +396,7 @@ export function EditorPanelContent({
|
||||||
setDownloading(true);
|
setDownloading(true);
|
||||||
try {
|
try {
|
||||||
const response = await authenticatedFetch(
|
const response = await authenticatedFetch(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/documents/${documentId}/download-markdown`,
|
`${BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/documents/${documentId}/download-markdown`,
|
||||||
{ method: "GET" }
|
{ method: "GET" }
|
||||||
);
|
);
|
||||||
if (!response.ok) throw new Error("Download failed");
|
if (!response.ok) throw new Error("Download failed");
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import { trackAnonymousChatMessageSent } from "@/lib/posthog/events";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { QuotaBar } from "./quota-bar";
|
import { QuotaBar } from "./quota-bar";
|
||||||
import { QuotaWarningBanner } from "./quota-warning-banner";
|
import { QuotaWarningBanner } from "./quota-warning-banner";
|
||||||
|
import { BACKEND_URL } from "@/lib/env-config";
|
||||||
interface Message {
|
interface Message {
|
||||||
id: string;
|
id: string;
|
||||||
role: "user" | "assistant";
|
role: "user" | "assistant";
|
||||||
|
|
@ -81,7 +81,7 @@ export function AnonymousChat({ model }: AnonymousChatProps) {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL || "http://localhost:8000"}/api/v1/public/anon-chat/stream`,
|
`${BACKEND_URL}/api/v1/public/anon-chat/stream`,
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ import { uploadFolderScan } from "@/lib/folder-sync-upload";
|
||||||
import { getSupportedExtensionsSet } from "@/lib/supported-extensions";
|
import { getSupportedExtensionsSet } from "@/lib/supported-extensions";
|
||||||
import { queries } from "@/zero/queries/index";
|
import { queries } from "@/zero/queries/index";
|
||||||
import { SidebarSlideOutPanel } from "./SidebarSlideOutPanel";
|
import { SidebarSlideOutPanel } from "./SidebarSlideOutPanel";
|
||||||
|
import { BACKEND_URL } from "@/lib/env-config";
|
||||||
|
|
||||||
const DesktopLocalTabContent = dynamic(
|
const DesktopLocalTabContent = dynamic(
|
||||||
() => import("./DesktopLocalTabContent").then((mod) => mod.DesktopLocalTabContent),
|
() => import("./DesktopLocalTabContent").then((mod) => mod.DesktopLocalTabContent),
|
||||||
|
|
@ -716,7 +717,7 @@ function AuthenticatedDocumentsSidebarBase({
|
||||||
.trim()
|
.trim()
|
||||||
.slice(0, 80) || "folder";
|
.slice(0, 80) || "folder";
|
||||||
await doExport(
|
await doExport(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/export?folder_id=${ctx.folder.id}`,
|
`${BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/export?folder_id=${ctx.folder.id}`,
|
||||||
`${safeName}.zip`
|
`${safeName}.zip`
|
||||||
);
|
);
|
||||||
toast.success(`Folder "${ctx.folder.name}" exported`);
|
toast.success(`Folder "${ctx.folder.name}" exported`);
|
||||||
|
|
@ -768,7 +769,7 @@ function AuthenticatedDocumentsSidebarBase({
|
||||||
.trim()
|
.trim()
|
||||||
.slice(0, 80) || "folder";
|
.slice(0, 80) || "folder";
|
||||||
await doExport(
|
await doExport(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/export?folder_id=${folder.id}`,
|
`${BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/export?folder_id=${folder.id}`,
|
||||||
`${safeName}.zip`
|
`${safeName}.zip`
|
||||||
);
|
);
|
||||||
toast.success(`Folder "${folder.name}" exported`);
|
toast.success(`Folder "${folder.name}" exported`);
|
||||||
|
|
@ -793,7 +794,7 @@ function AuthenticatedDocumentsSidebarBase({
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await authenticatedFetch(
|
const response = await authenticatedFetch(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/documents/${doc.id}/export?format=${format}`,
|
`${BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/documents/${doc.id}/export?format=${format}`,
|
||||||
{ method: "GET" }
|
{ method: "GET" }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Spinner } from "@/components/ui/spinner";
|
import { Spinner } from "@/components/ui/spinner";
|
||||||
import { authenticatedFetch, getBearerToken, redirectToLogin } from "@/lib/auth-utils";
|
import { authenticatedFetch, getBearerToken, redirectToLogin } from "@/lib/auth-utils";
|
||||||
|
import { BACKEND_URL, BACKEND_URL } from "@/lib/env-config";
|
||||||
const LARGE_DOCUMENT_THRESHOLD = 2 * 1024 * 1024; // 2MB
|
const LARGE_DOCUMENT_THRESHOLD = 2 * 1024 * 1024; // 2MB
|
||||||
|
|
||||||
interface DocumentContent {
|
interface DocumentContent {
|
||||||
|
|
@ -85,7 +85,7 @@ export function DocumentTabContent({ documentId, searchSpaceId, title }: Documen
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const url = new URL(
|
const url = new URL(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/documents/${documentId}/editor-content`
|
`${BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/documents/${documentId}/editor-content`
|
||||||
);
|
);
|
||||||
url.searchParams.set("max_length", String(LARGE_DOCUMENT_THRESHOLD));
|
url.searchParams.set("max_length", String(LARGE_DOCUMENT_THRESHOLD));
|
||||||
|
|
||||||
|
|
@ -143,7 +143,7 @@ export function DocumentTabContent({ documentId, searchSpaceId, title }: Documen
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
try {
|
try {
|
||||||
const response = await authenticatedFetch(
|
const response = await authenticatedFetch(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/documents/${documentId}/save`,
|
`${BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/documents/${documentId}/save`,
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
|
@ -285,7 +285,7 @@ export function DocumentTabContent({ documentId, searchSpaceId, title }: Documen
|
||||||
setDownloading(true);
|
setDownloading(true);
|
||||||
try {
|
try {
|
||||||
const response = await authenticatedFetch(
|
const response = await authenticatedFetch(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/documents/${documentId}/download-markdown`,
|
`${BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/documents/${documentId}/download-markdown`,
|
||||||
{ method: "GET" }
|
{ method: "GET" }
|
||||||
);
|
);
|
||||||
if (!response.ok) throw new Error("Download failed");
|
if (!response.ok) throw new Error("Download failed");
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import { Spinner } from "@/components/ui/spinner";
|
||||||
import { useMediaQuery } from "@/hooks/use-media-query";
|
import { useMediaQuery } from "@/hooks/use-media-query";
|
||||||
import { baseApiService } from "@/lib/apis/base-api.service";
|
import { baseApiService } from "@/lib/apis/base-api.service";
|
||||||
import { authenticatedFetch } from "@/lib/auth-utils";
|
import { authenticatedFetch } from "@/lib/auth-utils";
|
||||||
|
import { BACKEND_URL } from "@/lib/env-config";
|
||||||
|
|
||||||
function ReportPanelSkeleton() {
|
function ReportPanelSkeleton() {
|
||||||
return (
|
return (
|
||||||
|
|
@ -244,7 +245,7 @@ export function ReportPanelContent({
|
||||||
URL.revokeObjectURL(url);
|
URL.revokeObjectURL(url);
|
||||||
} else {
|
} else {
|
||||||
const response = await authenticatedFetch(
|
const response = await authenticatedFetch(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/reports/${activeReportId}/export?format=${format}`,
|
`${BACKEND_URL}/api/v1/reports/${activeReportId}/export?format=${format}`,
|
||||||
{ method: "GET" }
|
{ method: "GET" }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -277,7 +278,7 @@ export function ReportPanelContent({
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
try {
|
try {
|
||||||
const response = await authenticatedFetch(
|
const response = await authenticatedFetch(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/reports/${activeReportId}/content`,
|
`${BACKEND_URL}/api/v1/reports/${activeReportId}/content`,
|
||||||
{
|
{
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
|
@ -505,7 +506,7 @@ export function ReportPanelContent({
|
||||||
</div>
|
</div>
|
||||||
) : reportContent.content_type === "typst" ? (
|
) : reportContent.content_type === "typst" ? (
|
||||||
<PdfViewer
|
<PdfViewer
|
||||||
pdfUrl={`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}${shareToken ? `/api/v1/public/${shareToken}/reports/${activeReportId}/preview` : `/api/v1/reports/${activeReportId}/preview`}`}
|
pdfUrl={`${BACKEND_URL}${shareToken ? `/api/v1/public/${shareToken}/reports/${activeReportId}/preview` : `/api/v1/reports/${activeReportId}/preview`}`}
|
||||||
isPublic={isPublic}
|
isPublic={isPublic}
|
||||||
toolbarActions={
|
toolbarActions={
|
||||||
<>
|
<>
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import { searchSpacesApiService } from "@/lib/apis/search-spaces-api.service";
|
||||||
import { authenticatedFetch } from "@/lib/auth-utils";
|
import { authenticatedFetch } from "@/lib/auth-utils";
|
||||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||||
import { Spinner } from "../ui/spinner";
|
import { Spinner } from "../ui/spinner";
|
||||||
|
import { BACKEND_URL } from "@/lib/env-config";
|
||||||
|
|
||||||
interface GeneralSettingsManagerProps {
|
interface GeneralSettingsManagerProps {
|
||||||
searchSpaceId: number;
|
searchSpaceId: number;
|
||||||
|
|
@ -48,7 +49,7 @@ export function GeneralSettingsManager({ searchSpaceId }: GeneralSettingsManager
|
||||||
setIsExporting(true);
|
setIsExporting(true);
|
||||||
try {
|
try {
|
||||||
const response = await authenticatedFetch(
|
const response = await authenticatedFetch(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/export`,
|
`${BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/export`,
|
||||||
{ method: "GET" }
|
{ method: "GET" }
|
||||||
);
|
);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import { searchSpacesApiService } from "@/lib/apis/search-spaces-api.service";
|
||||||
import { authenticatedFetch } from "@/lib/auth-utils";
|
import { authenticatedFetch } from "@/lib/auth-utils";
|
||||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||||
import { Spinner } from "../ui/spinner";
|
import { Spinner } from "../ui/spinner";
|
||||||
|
import { BACKEND_URL } from "@/lib/env-config";
|
||||||
|
|
||||||
interface PromptConfigManagerProps {
|
interface PromptConfigManagerProps {
|
||||||
searchSpaceId: number;
|
searchSpaceId: number;
|
||||||
|
|
@ -54,7 +55,7 @@ export function PromptConfigManager({ searchSpaceId }: PromptConfigManagerProps)
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await authenticatedFetch(
|
const response = await authenticatedFetch(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/searchspaces/${searchSpaceId}`,
|
`${BACKEND_URL}/api/v1/searchspaces/${searchSpaceId}`,
|
||||||
{
|
{
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue