Thomas Kaul 1 day ago
committed by GitHub
parent
commit
212d0163a9
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      CHANGELOG.md
  2. 38
      apps/api/src/middlewares/html-template.middleware.ts

4
CHANGELOG.md

@ -22,6 +22,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Set the change detection strategy to `OnPush` in the registration page - Set the change detection strategy to `OnPush` in the registration page
- Set the change detection strategy to `OnPush` in the resources pages - Set the change detection strategy to `OnPush` in the resources pages
### Fixed
- Improved the error handling in the `HtmlTemplateMiddleware`
## 3.26.0 - 2026-07-14 ## 3.26.0 - 2026-07-14
### Added ### Added

38
apps/api/src/middlewares/html-template.middleware.ts

@ -97,20 +97,29 @@ export class HtmlTemplateMiddleware implements NestMiddleware {
private indexHtmlMap: { [languageCode: string]: string } = {}; private indexHtmlMap: { [languageCode: string]: string } = {};
public constructor(private readonly i18nService: I18nService) { public constructor(private readonly i18nService: I18nService) {
try { if (!environment.production) {
this.indexHtmlMap = SUPPORTED_LANGUAGE_CODES.reduce( return;
(map, languageCode) => ({
...map,
[languageCode]: readFileSync(
join(__dirname, '..', 'client', languageCode, 'index.html'),
'utf8'
)
}),
{}
);
} catch (error) {
this.logger.error('Failed to initialize index HTML map', error);
} }
this.indexHtmlMap = SUPPORTED_LANGUAGE_CODES.reduce((map, languageCode) => {
const indexHtmlPath = join(
__dirname,
'..',
'client',
languageCode,
'index.html'
);
try {
map[languageCode] = readFileSync(indexHtmlPath, 'utf8');
} catch {
this.logger.warn(
`Skipping language '${languageCode}': ${indexHtmlPath} not found`
);
}
return map;
}, {});
} }
public use(request: Request, response: Response, next: NextFunction) { public use(request: Request, response: Response, next: NextFunction) {
@ -118,7 +127,8 @@ export class HtmlTemplateMiddleware implements NestMiddleware {
let languageCode = path.substr(1, 2); let languageCode = path.substr(1, 2);
if ( if (
!(SUPPORTED_LANGUAGE_CODES as readonly string[]).includes(languageCode) !(SUPPORTED_LANGUAGE_CODES as readonly string[]).includes(languageCode) ||
!this.indexHtmlMap[languageCode]
) { ) {
languageCode = DEFAULT_LANGUAGE_CODE; languageCode = DEFAULT_LANGUAGE_CODE;
} }

Loading…
Cancel
Save