Skip to content

Commit d95cfff

Browse files
committed
Фронтенд: относительный путь для api
1 parent a9023b7 commit d95cfff

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

docker-compose.override.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ services:
1717
dockerfile: ./Dockerfile
1818
args:
1919
- VITE_YANDEX_METRICA_ID=${YANDEX_METRICA_ID}
20-
- VITE_BASE_PATH=https://hwproj.ru
2120

2221
rabbitmq:
2322
container_name: rabbitmq

hwproj.front/.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# Переменные, необходимые для локального запуска в режиме разработки (npm run dev)
2-
VITE_BASE_PATH=http://localhost:5000
32
VITE_YANDEX_METRICA_ID=101061418
43
WDS_SOCKET_PORT=0

hwproj.front/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ COPY . .
1616
# Устанвливаем переменные для production-сборки
1717
# Актуальные значения подтягиваются из docker-compose.override.yml
1818
ARG VITE_YANDEX_METRICA_ID
19-
ARG VITE_BASE_PATH
2019

2120
# Собираем статику в /usr/src/app/dist
2221
RUN npm run build

hwproj.front/src/api/ApiSingleton.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,20 @@ class Api {
5757
}
5858
}
5959

60-
const basePath = import.meta.env.VITE_BASE_PATH
60+
function getApiBase(): string {
61+
const {protocol, hostname, port} = window.location;
62+
63+
const isLocal =
64+
hostname === "localhost" ||
65+
hostname === "127.0.0.1" ||
66+
hostname === "::1";
67+
68+
const effectivePort = isLocal ? "5000" : (port || "");
69+
70+
return `${protocol}//${hostname}${effectivePort ? `:${effectivePort}` : ""}`
71+
}
72+
73+
const basePath = getApiBase()
6174
const authService = new AuthService()
6275

6376
let ApiSingleton: Api;

0 commit comments

Comments
 (0)