advweb-grp1 / advanced-web-final-year-project

Final year advanced web develop unit project
MIT License
1 stars 0 forks source link

fix: DEV env variable does not select the desired collection #49

Closed advweb-grp1 closed 1 year ago

advweb-grp1 commented 1 year ago

There is an issue with setting the DEV env variable in that the import will always default to _dev collections because the variable is treated as a string rather than a boolean. This means that the current implementation with constants:

export const collections = {
  hcm: import.meta.env.VITE_DEV ? 'hcm_dev' : 'hcm',
  user: import.meta.env.VITE_DEV ? 'users_dev' : 'user'
};

Will always use _dev

Solution

The solution is to treat the env as a string and match on 'true'. Then export the object at the end of the file like:


const collections = {};
if (import.meta.env.VITE_DEV == 'true'){
  collections.hcm = 'hcm_dev';
  collections.user = 'users_dev';
}else{
  collections.hcm = 'hcm';
  collections.user = 'user';
}
...
export{
  collections,
  fields
};