2021-08-25 01:25:49 +02:00
|
|
|
import { Inject, Injectable, Optional } from '@angular/core'
|
2021-07-25 14:00:22 +02:00
|
|
|
|
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
|
|
|
export class CommonService {
|
2021-08-25 01:25:49 +02:00
|
|
|
backendURL: string
|
|
|
|
|
|
|
|
|
|
constructor (@Inject('BACKEND_URL') @Optional() ssrBackendURL: string) {
|
|
|
|
|
const tag = (document.querySelector('meta[property=x-tabby-web-backend-url]') as HTMLMetaElement)
|
|
|
|
|
if (ssrBackendURL) {
|
|
|
|
|
this.backendURL = ssrBackendURL
|
|
|
|
|
tag.content = ssrBackendURL
|
|
|
|
|
} else {
|
|
|
|
|
if (tag.content && !tag.content.startsWith('{{')) {
|
|
|
|
|
this.backendURL = tag.content
|
|
|
|
|
} else {
|
|
|
|
|
this.backendURL = ''
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-25 14:00:22 +02:00
|
|
|
|
2021-08-25 01:25:49 +02:00
|
|
|
console.log(this.backendURL)
|
2021-07-25 17:44:43 +02:00
|
|
|
if (this.backendURL.endsWith('/')) {
|
|
|
|
|
this.backendURL = this.backendURL.slice(0, -1)
|
|
|
|
|
}
|
2021-07-25 14:00:22 +02:00
|
|
|
}
|
|
|
|
|
}
|