-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ng-universal-express): icon loader log errors
- Loading branch information
Showing
1 changed file
with
11 additions
and
3 deletions.
There are no files selected for viewing
14 changes: 11 additions & 3 deletions
14
projects/ng-universal-express/src/app/icon-load.ssr.strategy.ts
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 |
---|---|---|
@@ -1,12 +1,20 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { SvgLoadStrategy } from '@push-based/ngx-fast-svg'; | ||
import { readFileSync } from 'node:fs'; | ||
import { readFile } from 'node:fs'; | ||
import { resolve } from 'node:path'; | ||
import { Observable, of } from 'rxjs'; | ||
import { Observable } from 'rxjs'; | ||
|
||
@Injectable() | ||
export class IconLoadStrategySsr implements SvgLoadStrategy { | ||
load(url: string): Observable<string> { | ||
return of(readFileSync(resolve(url), 'utf8')); | ||
return new Observable<string>((observer) => { | ||
readFile(resolve(url), { encoding: 'utf8' }, (error, data) => { | ||
if (error) { | ||
observer.error(error); | ||
} else { | ||
observer.next(data); | ||
} | ||
}); | ||
}); | ||
} | ||
} |