full-stack-with-angular-and-spring-boot
full-stack-with-angular-and-spring-boot copied to clipboard
Different way to implement environment variables
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);
...
}
...
}
https://www.udemy.com/course/full-stack-application-development-with-spring-boot-and-angular/learn/#questions/15703804/
For what it's worth, here is my environment.ts:
// This file can be replaced during build by using the fileReplacements array.
// ng build --prod replaces environment.ts with environment.prod.ts.
// The list of file replacements can be found in angular.json.
export const environment = { production: false, api: { url: 'http://localhost:8585', jpa: 'http://localhost:8585/jpa', }, };
/*
- For easier debugging in development mode, you can import the following file
- to ignore zone related error stack frames such as
zone.run,zoneDelegate.invokeTask. - This import should be commented out in production mode because it will have a negative impact
- on performance if an error is thrown. */ // import 'zone.js/dist/zone-error'; // Included with Angular CLI. Lemme know if I can be of more help. Note that I have the tomcat configured to run on 8585 because 8080 is used by my local Jira.