diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f73db3..409a3a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,8 +29,8 @@ jobs: run: yarn run build env: NODE_ENV: development - VITE_SENTRY_DSN: https://0385edf7f78f4ad4a511abae516ae3e8@sentry.biip.lt/7 VITE_MAPS_HOST: https://dev.maps.biip.lt + ZUVINIMAS_API_BASE_URL: https://dev.zuvinimas.biip.lt/api - uses: actions/upload-artifact@v4 with: diff --git a/src/environment.d.ts b/src/environment.d.ts new file mode 100644 index 0000000..6205ad3 --- /dev/null +++ b/src/environment.d.ts @@ -0,0 +1,16 @@ +declare global { + namespace NodeJS { + interface ProcessEnv { + NODE_ENV: 'development' | 'production'; + ZUVINIMAS_API_BASE_URL?: string; + VITE_SENTRY_DSN?: string; + VITE_ENVIRONMENT?: string; + VITE_MAPS_HOST?: string; + VITE_VERSION?: string; + } + } +} + +// If this file has no import/export statements (i.e. is a script) +// convert it into a module by adding an empty export statement. +export {}; diff --git a/src/utils/api.ts b/src/utils/api.ts index bad6435..de3d8d1 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -5,6 +5,7 @@ import { FishStocking, FishType, Tenant, TenantUser, User } from './types'; import { isEmpty } from 'lodash'; import Cookies from 'universal-cookie'; import { Resources } from './constants'; + const cookies = new Cookies(); interface GetAll { @@ -57,6 +58,7 @@ interface GetOne { populate?: string[]; scope?: string; } + interface UpdateOne { resource?: string; id?: string; @@ -76,10 +78,14 @@ interface Create { class Api { private AuthApiAxios: AxiosInstance; - private readonly proxy: string = '/api'; + private readonly apiBaseUrl: string; constructor() { - this.AuthApiAxios = Axios.create(); + this.apiBaseUrl = process.env.ZUVINIMAS_API_BASE_URL ?? '/api'; + + this.AuthApiAxios = Axios.create({ + baseURL: this.apiBaseUrl, + }); this.AuthApiAxios.interceptors.request.use( (config) => { const token = cookies.get('token'); @@ -88,7 +94,6 @@ class Api { config.headers!.Authorization = 'Bearer ' + token; if (isFinite(parseInt(profileId))) config.headers!['X-Profile'] = profileId; } - config.url = this.proxy + config.url; return config; }, (error) => { @@ -413,7 +418,7 @@ class Api { const profileId = cookies.get('profileId'); const response = await fetch( - `${this.proxy}/${Resources.EXCEL}?filter=${JSON.stringify(filter)}`, + `${this.apiBaseUrl}/${Resources.EXCEL}?filter=${JSON.stringify(filter)}`, { headers: { 'Content-Type': 'application/json',