pledge4future / WePledge

WebApp to calculate work related CO2e emissions from heating and electricity consumption as well as business trips and commuting.
https://pledge4future.org
GNU General Public License v3.0
6 stars 2 forks source link

Create setup switch for local dev setup and deployed setup #327

Open codingfabi opened 1 year ago

codingfabi commented 1 year ago

Currently we root the backend requests in the apollo client dependent on the environment variable NEXT_PUBLIC_DEV:

JSON.parse(process.env.NEXT_PUBLIC_DEV ? process.env.NEXT_PUBLIC_DEV  as string : 'false' ) ? `http://localhost:8000/graphql/` : `https://api.test-pledge4future.heigit.org/graphql/`

This could lead to problems when deploying the software on the production service because https://api.test-pledge4future.heigit.org/graphql/ will then no longer be the valid url for the backend.

To overcome this problem, I suggest to remove the NEXT_PUBLIC_DEV environment variable and introduce a new one called 'NEXT_PUBLIC_INSTANCE`. We can then specify a string for this variable that specifies, wether the application is hosted in a local dev setup, in the test instance or the production instance.

We define three valid strings: p4f-local, p4f-test and p4f-prod. With these values, we can then get the following constellations with the resulting API url defined by a function that looks like this:

function getURLApi(){
     switch(process.env.NEXT_PUBLIC_DEV):
               case 'p4f-local':
                          return 'http://localhost:8000/graphql/'
                case 'p4f-test':
                           return 'https://api.test-pledge4future.heigit.org/graphql/'
                case 'p4f-prod:
                           return 'https://api.pledge4future.heigit.org/graphql/'
}
codingfabi commented 1 year ago

@redfrexx @sami1riaz let me know what you guys think :)

redfrexx commented 1 year ago

Sounds good! I think it would be good to put the URLS into the .env file as well, so that in case we have to change them we don't have to search in the code.

redfrexx commented 1 year ago

We could also shorten them to local, test and prod.