Skip to content
Merged
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
4 changes: 3 additions & 1 deletion app/src/components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import Typography from '@mui/material/Typography';

import { CONFIG } from 'src/global-config';

interface Props {
children: ReactNode;
fallback?: ReactNode;
Expand Down Expand Up @@ -210,7 +212,7 @@ export class ErrorBoundary extends Component<Props, State> {
</Typography>
)}

{componentStack && import.meta.env.DEV && !showDetails && (
{componentStack && CONFIG.isDev && !showDetails && (
<Typography
variant="caption"
sx={{ mt: 1, display: 'block', color: 'var(--ink-muted)' }}
Expand Down
3 changes: 2 additions & 1 deletion app/src/components/RouteErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Button from '@mui/material/Button';
import CircularProgress from '@mui/material/CircularProgress';
import Typography from '@mui/material/Typography';

import { CONFIG } from 'src/global-config';
import { NotFoundPage } from 'src/pages/NotFoundPage';

const RELOAD_ATTEMPT_KEY = 'anyplot:chunk-reload-attempt';
Expand Down Expand Up @@ -142,7 +143,7 @@ export function RouteErrorBoundary() {
<Typography variant="body2" sx={{ color: 'var(--ink-muted)' }}>
{body}
</Typography>
{import.meta.env.DEV && (
{CONFIG.isDev && (
<Typography
variant="caption"
component="pre"
Expand Down
11 changes: 6 additions & 5 deletions app/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Constants for anyplot.ai frontend

export const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:8000';
// DebugPage uses this — set to "/api" in prod (same-origin via the
// Cloudflare Worker on anyplot.ai/api/*) so the CF Access cookie can be
// sent with fetch. Falls back to API_URL locally where there's no Worker.
export const DEBUG_API_URL = import.meta.env.VITE_DEBUG_API_URL || API_URL;
import { CONFIG } from 'src/global-config';

export { CONFIG };
// Compat aliases — prefer CONFIG.api.* in new code.
export const API_URL = CONFIG.api.baseUrl;
export const DEBUG_API_URL = CONFIG.api.debugBaseUrl;
export const GITHUB_URL = 'https://github.com/MarkusNeusinger/anyplot';
export const LIBRARIES = [
'altair',
Expand Down
27 changes: 27 additions & 0 deletions app/src/global-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import packageJson from '../package.json';

interface GlobalConfig {
appName: string;
appVersion: string;
api: {
baseUrl: string;
debugBaseUrl: string;
};
isDev: boolean;
}

const apiBaseUrl = import.meta.env.VITE_API_URL || 'http://localhost:8000';

export const CONFIG: GlobalConfig = {
appName: 'anyplot',
appVersion: packageJson.version,
api: {
baseUrl: apiBaseUrl,
// DebugPage uses this — set to "/api" in prod (same-origin via the
// Cloudflare Worker on anyplot.ai/api/*) so the CF Access cookie can be
// sent with fetch. Falls back to the API base locally where there's no
// Worker.
debugBaseUrl: import.meta.env.VITE_DEBUG_API_URL || apiBaseUrl,
},
isDev: import.meta.env.DEV,
};
4 changes: 2 additions & 2 deletions app/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly VITE_API_URL: string;
readonly VITE_DEBUG_API_URL: string;
readonly VITE_API_URL?: string;
readonly VITE_DEBUG_API_URL?: string;
}

interface ImportMeta {
Expand Down
Loading