Skip to content

Different way to implement environment variables #8

@in28minutes

Description

@in28minutes

cool. Here is my code for environment.ts, as a suggestion:

export const environment = {
production: false,
api: {
url: 'http://localhost:8585',
jpa: 'http://localhost:8585/jpa',
},
};
of course, the port for your setup will not stay 8585, so feel free to adapt it heavily ;-)

You basically use it in two places, basic-authentication.service and todo-data.service. In basic there is only one instance, in todo-data a couple, so I am just posting a few lines of todo-date as an example. In your version I sort of like that it uses all UPPERCASE because those are constants. This is not the way environment.ts is implemented, though, so you would have to live with lowercase:

import { environment } from 'src/environments/environment';

...

export class TodoDataService {
...
retrieveAllTodos(username) {
return this.http.get<Todo[]>(${environment.api.jpa}/users/${username}/todos);
...
}
...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions