Skip to content

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

@codingfabi

Description

@codingfabi

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/'
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    DiscussionThinks that need to be discussedoperationsconsists of all issues that regard application building and hosting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions