Skip to content

Commit 56d9e6d

Browse files
committed
Added .env for a baseUrl and applied that to all calls to the backend
1 parent 7dd806b commit 56d9e6d

File tree

8 files changed

+29
-16
lines changed

8 files changed

+29
-16
lines changed

src/main/frontend/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_API_BASE_URL=/

src/main/frontend/.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_API_BASE_URL=/

src/main/frontend/.env.production

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Change to actual production API URL
2+
VITE_API_BASE_URL=https://api.wearefrank.com/

src/main/frontend/app/routes/configurations/add-configuration-modal.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ export default function AddConfigurationModal({
1919
const [error, setError] = useState<string | null>(null)
2020
const [filename, setFilename] = useState<string>('')
2121
const setProject = useProjectStore((s) => s.setProject)
22+
const baseUrl = import.meta.env.VITE_API_BASE_URL
2223

2324
const handleAdd = async () => {
2425
setLoading(true)
2526
setError(null)
27+
2628
try {
2729
let configname = filename.trim()
2830
if (!configname) {
@@ -35,7 +37,10 @@ export default function AddConfigurationModal({
3537
configname = `${configname}.xml`
3638
}
3739

38-
const url = `http://localhost:8080/projects/${encodeURIComponent(currentProject.name)}/configurations/${encodeURIComponent(configname)}`
40+
const url = `${baseUrl}projects/${encodeURIComponent(
41+
currentProject.name,
42+
)}/configurations/${encodeURIComponent(configname)}`
43+
3944
const response = await fetch(url, {
4045
method: 'POST',
4146
headers: { 'Content-Type': 'application/json' },
@@ -66,9 +71,12 @@ export default function AddConfigurationModal({
6671
<p className="mb-4">Add a new configuration file.</p>
6772

6873
<div className="mb-4 flex items-center gap-2">
69-
<label className="text-sm font-medium">Filename</label>
74+
<label className="text-sm font-medium" htmlFor="configuration-filename-input">
75+
Filename
76+
</label>
7077
<div className="ml-2 flex w-full items-center">
7178
<input
79+
id="configuration-filename-input"
7280
value={filename}
7381
onChange={(event) => setFilename(event.target.value)}
7482
className="border-border bg-background focus:border-foreground-active focus:ring-foreground-active w-full rounded border px-2 py-1 text-sm transition focus:ring-2 focus:outline-none"

src/main/frontend/app/routes/configurations/add-configuration-tile.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ export default function AddConfigurationTile({ onClick }: Readonly<AddConfigurat
77
<div
88
className="border-border hover:bg-backdrop hover:text-foreground-active relative m-2 h-50 w-40 cursor-pointer rounded border p-4"
99
onClick={onClick}
10+
title="New Configuration"
1011
>
11-
{/* top-left label */}
12-
1312
{/* big plus centered */}
1413
<div className="absolute inset-0 flex items-center justify-center">
1514
<span className="text-4xl leading-none font-extrabold">+</span>

src/main/frontend/app/routes/editor/editor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default function CodeEditor() {
2525
const editorReference = useRef<Parameters<OnMount>[0] | null>(null)
2626
const decorationIdsReference = useRef<string[]>([])
2727
const [isSaving, setIsSaving] = useState(false)
28+
const baseUrl = import.meta.env.VITE_API_BASE_URL
2829

2930
const handleEditorMount: OnMount = (editor, monacoInstance) => {
3031
editorReference.current = editor
@@ -237,7 +238,8 @@ export default function CodeEditor() {
237238
setIsSaving(true)
238239

239240
try {
240-
const response = await fetch(`/projects/${project.name}/${configName}`, {
241+
const url = `${baseUrl}projects/${project.name}/${configName}`
242+
const response = await fetch(url, {
241243
method: 'PUT',
242244
headers: { 'Content-Type': 'application/json' },
243245
body: JSON.stringify({ xmlContent: updatedXml }),

src/main/frontend/app/routes/projectlanding/project-landing.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ export default function ProjectLanding() {
2222
const [showModal, setShowModal] = useState(false)
2323
const setProject = useProjectStore((state) => state.setProject)
2424
const location = useLocation()
25+
const baseUrl = import.meta.env.VITE_API_BASE_URL
2526

2627
useEffect(() => {
2728
const fetchProjects = async () => {
2829
try {
29-
const response = await fetch('http://localhost:8080/projects')
30+
const response = await fetch(`${baseUrl}projects`)
3031
if (!response.ok) {
3132
throw new Error(`HTTP error! Status: ${response.status}`)
3233
}
@@ -49,7 +50,7 @@ export default function ProjectLanding() {
4950

5051
const createProject = async (projectName: string) => {
5152
try {
52-
const response = await fetch(`http://localhost:8080/projects/${projectName}`, {
53+
const response = await fetch(`${baseUrl}projects/${projectName}`, {
5354
method: 'POST',
5455
headers: {
5556
'Content-Type': 'application/json',

src/main/frontend/app/routes/studio/canvas/flow.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import CreateNodeModal from '~/components/flow/create-node-modal'
3030
import { useProjectStore } from '~/stores/project-store'
3131
import { toast, ToastContainer } from 'react-toastify'
3232
import { useTheme } from '~/hooks/use-theme'
33+
const baseUrl = import.meta.env.VITE_API_BASE_URL
3334

3435
export type FlowNode = FrankNode | ExitNode | StickyNote | GroupNode | Node
3536

@@ -513,20 +514,18 @@ function FlowCanvas({ showNodeContextMenu }: Readonly<{ showNodeContextMenu: (b:
513514

514515
try {
515516
if (!project) return
516-
const response = await fetch(
517-
`/projects/${encodeURIComponent(project.name)}/${encodeURIComponent(configName)}/adapters/${encodeURIComponent(activeTabName)}`,
518-
{
517+
const url = `/projects/${encodeURIComponent(project.name)}/${encodeURIComponent(configName)}/adapters/${encodeURIComponent(activeTabName)}`
518+
const response = await fetch(url, {
519519
method: 'PUT',
520520
headers: { 'Content-Type': 'application/json' },
521521
body: JSON.stringify({ adapterXml: xmlString }),
522-
}
523-
)
522+
})
524523

525-
if (!response.ok) {
526-
throw new Error(`HTTP error! Status: ${response.status}`)
527-
}
524+
if (!response.ok) {
525+
throw new Error(`HTTP error! Status: ${response.status}`)
526+
}
528527

529-
toast.success('Flow saved successfully!')
528+
toast.success('Flow saved successfully!')
530529
} catch (error) {
531530
console.error('Failed to save XML:', error)
532531
toast.error(`Failed to save XML: ${error}`)

0 commit comments

Comments
 (0)