From 524dc010d0212d9c63c68e036067627069a9a8e4 Mon Sep 17 00:00:00 2001 From: philipredstone Date: Tue, 15 Apr 2025 14:26:10 +0200 Subject: [PATCH] auto discover url in frontend --- .gitignore | 9 +++++++++ frontend/src/api/auth.ts | 6 +++++- frontend/src/api/network.ts | 6 +++++- frontend/src/api/people.ts | 6 +++++- frontend/src/api/relationships.ts | 6 +++++- 5 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f16712a --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +frontend/node_modules +frontend/dist +frontend/.env +frontend/bun.lockb + +node_modules +dist +.env +bun.lockb \ No newline at end of file diff --git a/frontend/src/api/auth.ts b/frontend/src/api/auth.ts index a30e508..9118d09 100644 --- a/frontend/src/api/auth.ts +++ b/frontend/src/api/auth.ts @@ -1,6 +1,10 @@ import axios from 'axios'; -const API_URL = process.env.REACT_APP_API_URL || 'http://localhost:5000/api'; +const protocol = window.location.protocol; +const hostname = window.location.hostname; +const port = window.location.port; + +const API_URL = protocol + '//' + hostname + (port ? ':' + port : '') + '/api'; // Configure axios axios.defaults.withCredentials = true; diff --git a/frontend/src/api/network.ts b/frontend/src/api/network.ts index dd68129..0fe4de8 100644 --- a/frontend/src/api/network.ts +++ b/frontend/src/api/network.ts @@ -1,6 +1,10 @@ import axios from 'axios'; -const API_URL = process.env.REACT_APP_API_URL || 'http://localhost:5000/api'; +const protocol = window.location.protocol; +const hostname = window.location.hostname; +const port = window.location.port; + +const API_URL = protocol + '//' + hostname + (port ? ':' + port : '') + '/api'; // Types export interface Network { diff --git a/frontend/src/api/people.ts b/frontend/src/api/people.ts index c4fd419..9c39dc5 100644 --- a/frontend/src/api/people.ts +++ b/frontend/src/api/people.ts @@ -1,6 +1,10 @@ import axios from 'axios'; -const API_URL = process.env.REACT_APP_API_URL || 'http://localhost:5000/api'; +const protocol = window.location.protocol; +const hostname = window.location.hostname; +const port = window.location.port; + +const API_URL = protocol + '//' + hostname + (port ? ':' + port : '') + '/api'; // Types export interface Person { diff --git a/frontend/src/api/relationships.ts b/frontend/src/api/relationships.ts index a4fc6ba..a26d81a 100644 --- a/frontend/src/api/relationships.ts +++ b/frontend/src/api/relationships.ts @@ -1,6 +1,10 @@ import axios from 'axios'; -const API_URL = process.env.REACT_APP_API_URL || 'http://localhost:5000/api'; +const protocol = window.location.protocol; +const hostname = window.location.hostname; +const port = window.location.port; + +const API_URL = protocol + '//' + hostname + (port ? ':' + port : '') + '/api'; // Types export interface Relationship {