Skip to content

Commit

Permalink
Fixes .env issues and creates a safety net while building
Browse files Browse the repository at this point in the history
  • Loading branch information
Meefish committed Jan 20, 2025
1 parent e97f62e commit 01b20ca
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
8 changes: 8 additions & 0 deletions check-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const dotenv = require('dotenv');
dotenv.config();

if (!process.env.REACT_APP_BASE_URL) {
console.error('Error: REACT_APP_BASE_URL is not defined. Build failed...');
process.exit(1);
}
console.log('REACT_APP_BASE_URL found ' + process.env.REACT_APP_BASE_URL);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"build": "node check-env.js && react-scripts build",
"test": "jest",
"test:unit": "jest --config=jest.config.js --runTestsByPath \"**/*.unit.test.tsx\"",
"test:integration": "jest --config=jest.config.js --runTestsByPath \"**/*.integration.test.tsx\"",
Expand Down
3 changes: 1 addition & 2 deletions src/services/authService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { getMyProfile } from './profileService';
import { getBaseUrl } from '../config';

const TEST_BASE_URL = 'https://wildlifenl-uu-michi011.apps.cl01.cp.its.uu.nl';
const BASE_URL = process.env.NODE_ENV === 'test'
? TEST_BASE_URL
: getBaseUrl();
: process.env.REACT_APP_BASE_URL;

const API_URL = `${BASE_URL}/auth/`;

Expand Down
3 changes: 1 addition & 2 deletions src/services/experimentService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Experiment, UpdateExperiment } from '../types/experiment';
import { getBaseUrl } from '../config';

const TEST_BASE_URL = 'https://wildlifenl-uu-michi011.apps.cl01.cp.its.uu.nl';
const BASE_URL = process.env.NODE_ENV === 'test'
? TEST_BASE_URL
: getBaseUrl();
: process.env.REACT_APP_BASE_URL;

const EXPERIMENT_API_URL = `${BASE_URL}/experiment/`;
const EXPERIMENTS_API_URL = `${BASE_URL}/experiments/`;
Expand Down
3 changes: 1 addition & 2 deletions src/services/livingLabService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { LivingLab } from '../types/livinglab';
import { getBaseUrl } from '../config';

const TEST_BASE_URL = 'https://wildlifenl-uu-michi011.apps.cl01.cp.its.uu.nl';
const BASE_URL = process.env.NODE_ENV === 'test'
? TEST_BASE_URL
: getBaseUrl();
: process.env.REACT_APP_BASE_URL;


const API_URL = `${BASE_URL}/livinglabs`;
Expand Down

0 comments on commit 01b20ca

Please sign in to comment.