Skip to content

Commit

Permalink
Merge branch 'main' into 52-srifto-pataisymas
Browse files Browse the repository at this point in the history
  • Loading branch information
DovMa committed Feb 16, 2024
2 parents e4fab74 + 03a414d commit 90fa274
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 19 deletions.
40 changes: 34 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ name: Continuous integration

on:
push:
branches: [main]
branches: [ main ]
pull_request:

jobs:
build-test:
name: Build and test
runs-on: ubuntu-latest
timeout-minutes: 15

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: package.json
cache: yarn
Expand All @@ -27,16 +26,45 @@ jobs:
run: yarn test --passWithNoTests

- name: Build
run: yarn run build
run: yarn run build --mode development
env:
NODE_ENV: development
VITE_MAPS_HOST: https://dev.maps.biip.lt
VITE_ZUVINIMAS_API_BASE_URL: https://dev.zuvinimas.biip.lt/api

- uses: actions/upload-artifact@v4
with:
name: page
path: dist

validate-docker-build:
name: Validate if docker image builds
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Build & tag docker image
uses: AplinkosMinisterija/reusable-workflows/.github/actions/docker-build-tag-push@main
with:
environment: test
push: false

publish-preview:
name: Publish preview
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
timeout-minutes: 10
needs: build-test
permissions:
contents: read
deployments: write
steps:
- uses: actions/checkout@v4

- name: Publish preview to Cloudflare pages
uses: AplinkosMinisterija/reusable-workflows/.github/actions/cloudflare-pages-publish@main
with:
cloudflare-api-token: ${{ secrets.BIIP_CLOUDFLARE_PAGES_API_TOKEN }}
cloudflare-account-id: ${{ secrets.BIIP_CLOUDFLARE_ACCOUNT_ID }}
cloudflare-project-name: biip-zuvinimas-web
artifact-name: page
26 changes: 13 additions & 13 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ 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();
const env = import.meta.env;

interface GetAll {
resource?: string;
Expand Down Expand Up @@ -57,6 +59,7 @@ interface GetOne {
populate?: string[];
scope?: string;
}

interface UpdateOne {
resource?: string;
id?: string;
Expand All @@ -74,29 +77,23 @@ interface Create {
id?: string;
}

const token = cookies.get('token');
const profileId = cookies.get('profileId');

class Api {
private AuthApiAxios: AxiosInstance;
private readonly proxy: string = '/api';
private readonly apiBaseUrl: string;

constructor() {
this.AuthApiAxios = Axios.create();
this.apiBaseUrl = env.VITE_ZUVINIMAS_API_BASE_URL ?? '/api';

this.AuthApiAxios = Axios.create();
this.AuthApiAxios.interceptors.request.use(
(config) => {
if (!config.url) {
return config;
}

config.url = this.proxy + config.url;
const token = cookies.get('token');
const profileId = cookies.get('profileId');
if (token) {
config.headers!.Authorization = 'Bearer ' + token;

if (isFinite(parseInt(profileId))) config.headers!['X-Profile'] = profileId;
}

config.url = this.apiBaseUrl + config.url;
return config;
},
(error) => {
Expand Down Expand Up @@ -417,8 +414,11 @@ class Api {
};

getExcel = async ({ filter }: TableList): Promise<any> => {
const token = cookies.get('token');
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
14 changes: 14 additions & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly NODE_ENV: 'development' | 'production';
readonly VITE_ZUVINIMAS_API_BASE_URL?: string;
readonly VITE_SENTRY_DSN?: string;
readonly VITE_ENVIRONMENT?: string;
readonly VITE_MAPS_HOST?: string;
readonly VITE_VERSION?: string;
}

interface ImportMeta {
readonly env: ImportMetaEnv;
}

0 comments on commit 90fa274

Please sign in to comment.