Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview builds using cloudflare pages #53

Merged
merged 8 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 8 additions & 3 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 @@ -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) => {
Expand All @@ -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) => {
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
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;
}
Loading