diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5df5d4a..a196905 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: Continuous integration on: push: - branches: [main] + branches: [ main ] pull_request: jobs: @@ -10,12 +10,11 @@ jobs: 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 @@ -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 diff --git a/src/utils/api.ts b/src/utils/api.ts index bad6435..7a612b1 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -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; @@ -57,6 +59,7 @@ interface GetOne { populate?: string[]; scope?: string; } + interface UpdateOne { resource?: string; id?: string; @@ -76,9 +79,11 @@ interface Create { class Api { private AuthApiAxios: AxiosInstance; - private readonly proxy: string = '/api'; + private readonly apiBaseUrl: string; constructor() { + this.apiBaseUrl = env.VITE_ZUVINIMAS_API_BASE_URL ?? '/api'; + this.AuthApiAxios = Axios.create(); this.AuthApiAxios.interceptors.request.use( (config) => { @@ -88,7 +93,7 @@ class Api { config.headers!.Authorization = 'Bearer ' + token; if (isFinite(parseInt(profileId))) config.headers!['X-Profile'] = profileId; } - config.url = this.proxy + config.url; + config.url = this.apiBaseUrl + 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', diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts new file mode 100644 index 0000000..f38a662 --- /dev/null +++ b/src/vite-env.d.ts @@ -0,0 +1,14 @@ +/// + +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; +}