feat: UrlService um Routen- und URL-Methoden erweitert, die environments verwenden

This commit is contained in:
Developer 02
2024-07-22 15:56:21 +02:00
parent 3a3df2e7f1
commit 4d350bf6e8
2 changed files with 33 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
import { Injectable, Inject, inject } from '@angular/core';
import { DOCUMENT } from '@angular/common';
import { Meta } from '@angular/platform-browser';
import { env } from '../../environments/environment';
@Injectable({
providedIn: 'root'
@@ -8,7 +9,7 @@ import { Meta } from '@angular/platform-browser';
export class UrlService {
document: Document;
meta: Meta;
constructor() {
this.document = inject(DOCUMENT)
this.meta = inject(Meta)
@@ -19,8 +20,22 @@ export class UrlService {
return baseElement?.getAttribute('href') || '/';
}
getApiUrl(): string | null {
const apiMetaTag = this.meta.getTag('name="api-url"');
return apiMetaTag ? apiMetaTag.content : null;
getApiUrl(route: string = ""): string | null {
return env.api_url + route;
}
readonly apiRoute = {
user: this.getApiUrl(env.routes.user),
group: this.getApiUrl(env.routes.group),
module: this.getApiUrl(env.routes.module),
moduleOfUser: this.getApiUrl(env.routes.moduleOfUser),
groupOfUser: this.getApiUrl(env.routes.groupOfUser),
userRep: this.getApiUrl(env.routes.userRep),
dirGroup: this.getApiUrl(env.routes.dirGroup),
dirUser: this.getApiUrl(env.routes.dirUser),
directory: this.getApiUrl(env.routes.directory),
login: this.getApiUrl(env.routes.login),
logout: this.getApiUrl(env.routes.logout),
loginCheck: this.getApiUrl(env.routes.loginCheck)
};
}