Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add badge for the current environnement
- Loading branch information
1 parent
ee5a619
commit ce6e432
Showing
8 changed files
with
72 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { FactoryProvider, InjectionToken } from '@angular/core'; | ||
|
||
export const WINDOW = new InjectionToken<Window>('window'); | ||
|
||
const windowProvider: FactoryProvider = { | ||
provide: WINDOW, | ||
useFactory: () => window | ||
}; | ||
|
||
export const WINDOW_PROVIDERS = [windowProvider]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Inject, Injectable } from '@angular/core'; | ||
import { WINDOW } from '@app/core/window.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class PreviewBadgeService { | ||
badge = 'BETA'; | ||
|
||
constructor(@Inject(WINDOW) private readonly window: Window) {} | ||
|
||
computeBadge() { | ||
try { | ||
const hostname = this.window.location.hostname; | ||
if ( | ||
hostname === 'localhost' || | ||
hostname === '127.0.0.1' || | ||
hostname === '0.0.0.0' | ||
) { | ||
return 'LOCAL PREVIEW'; | ||
} else if (hostname.startsWith('next.')) { | ||
return 'MASTER PREVIEW'; | ||
} else if (hostname.includes('netlify')) { | ||
return 'PR PREVIEW'; | ||
} | ||
|
||
return this.badge; | ||
} catch (errror) { | ||
return this.badge; | ||
} | ||
} | ||
} |