-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug(SSR): npm run prerender fails with HttpErrorResponse #703
Comments
Somebody know how to do prerendering with transloco ? |
Heyo, I solved this by providing a special TranslocoLoader only for the server. I already use this in production with success. @NgModule({
imports: [AppModule, ServerModule, IonicServerModule],
providers: [
{ provide: TRANSLOCO_LOADER, useClass: TranslocoServerHttpLoaderService },
],
bootstrap: [AppComponent],
})
export class AppServerModule {} The loader itself don't tries to get the JSON files by using a HTTP call and just uses the file system: @Injectable({
providedIn: 'root',
})
export class TranslocoServerHttpLoaderService implements TranslocoLoader {
getTranslation(lang: string): Observable<Translation> {
const assetsFolder = join(
process.cwd(),
'dist',
'app',
'browser',
'assets',
'i18n',
);
return of(
JSON.parse(fs.readFileSync(`${assetsFolder}/${lang}.json`, 'utf8')),
);
}
} With this solution I managed it to prerender the files for different languages. |
Had a similar issue in an existing app, the new pre-rendering done in i.e changing return this.http.get<Translation>(`${environment["baseUrl"]}/assets/i18n/${lang}.json`); to return this.http.get<Translation>(`/assets/i18n/${lang}.json`); |
thanks. my project angular v17 with ssr without standalone. solved my problem |
No updates on this issue? |
@limes @mackelito Did you try the solution @NLueg suggested? |
Is there an existing issue for this?
Which Transloco package(s) are the source of the bug?
Transloco
Is this a regression?
No
Current behavior
Expected behavior
Prerender process should work the same way as
ng build && ng run {app-name}:server
Please provide a link to a minimal reproduction of the bug, if you won't provide a link the issue won't be handled.
See current behavior (1-3)
Transloco Config
Please provide the environment you discovered this bug in
Browser
Additional context
No response
I would like to make a pull request for this bug
No
The text was updated successfully, but these errors were encountered: