26 lines
638 B
TypeScript
26 lines
638 B
TypeScript
import { Injectable, Inject, inject } from '@angular/core';
|
|
import { DOCUMENT } from '@angular/common';
|
|
import { Meta } from '@angular/platform-browser';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class UrlService {
|
|
document: Document;
|
|
meta: Meta;
|
|
|
|
constructor() {
|
|
this.document = inject(DOCUMENT)
|
|
this.meta = inject(Meta)
|
|
}
|
|
|
|
getBaseHref(): string {
|
|
const baseElement = this.document.querySelector('base');
|
|
return baseElement?.getAttribute('href') || '/';
|
|
}
|
|
|
|
getApiUrl(): string | null {
|
|
const apiMetaTag = this.meta.getTag('name="api-url"');
|
|
return apiMetaTag ? apiMetaTag.content : null;
|
|
}
|
|
} |