Skip to content

Commit

Permalink
Base url from env
Browse files Browse the repository at this point in the history
  • Loading branch information
vycius committed Feb 9, 2024
1 parent 84caf82 commit b93cb8b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions src/environment.d.ts
Original file line number Diff line number Diff line change
@@ -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 {};
13 changes: 9 additions & 4 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -57,6 +58,7 @@ interface GetOne {
populate?: string[];
scope?: string;
}

interface UpdateOne {
resource?: string;
id?: string;
Expand All @@ -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');
Expand All @@ -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) => {
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit b93cb8b

Please sign in to comment.