diff --git a/apps/api/src/app/app.module.ts b/apps/api/src/app/app.module.ts index 4bdd50c9e8..bd76ef49b4 100644 --- a/apps/api/src/app/app.module.ts +++ b/apps/api/src/app/app.module.ts @@ -14,8 +14,6 @@ import { DataGatheringQueueModule } from '@ghostfolio/api/services/queues/data-g import { PortfolioSnapshotQueueModule } from '@ghostfolio/api/services/queues/portfolio-snapshot/portfolio-snapshot.module'; import { BULL_BOARD_ROUTE, - DEFAULT_LANGUAGE_CODE, - SUPPORTED_LANGUAGE_CODES, THROTTLE_DEFAULT_LIMIT, THROTTLE_DEFAULT_TTL } from '@ghostfolio/common/config'; @@ -143,29 +141,7 @@ import { UserModule } from './user/user.module'; '/api/*wildcard', '/sitemap.xml' ], - rootPath: join(__dirname, '..', 'client'), - serveStaticOptions: { - setHeaders: (res) => { - if (res.req?.path === '/') { - let languageCode = DEFAULT_LANGUAGE_CODE; - - try { - const code = res.req.headers['accept-language'] - .split(',')[0] - .split('-')[0]; - - if ( - (SUPPORTED_LANGUAGE_CODES as readonly string[]).includes(code) - ) { - languageCode = code; - } - } catch {} - - res.set('Location', `/${languageCode}`); - res.statusCode = StatusCodes.MOVED_PERMANENTLY; - } - } - } + rootPath: join(__dirname, '..', 'client') }), ServeStaticModule.forRoot({ rootPath: join(__dirname, '..', 'client', '.well-known'), diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index 33ad032e98..77d571ea0b 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -1,3 +1,4 @@ +import { languageRedirectMiddleware } from '@ghostfolio/api/middlewares/language-redirect.middleware'; import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; import { BULL_BOARD_ROUTE, @@ -100,6 +101,8 @@ async function bootstrap() { }); } + app.use(languageRedirectMiddleware); + const configurationService = app.get(ConfigurationService); const trustProxy = configurationService.get('TRUST_PROXY'); diff --git a/apps/api/src/middlewares/html-template.middleware.ts b/apps/api/src/middlewares/html-template.middleware.ts index bdace34024..928a9f22c5 100644 --- a/apps/api/src/middlewares/html-template.middleware.ts +++ b/apps/api/src/middlewares/html-template.middleware.ts @@ -111,7 +111,13 @@ export class HtmlTemplateMiddleware implements NestMiddleware { ); try { - map[languageCode] = readFileSync(indexHtmlPath, 'utf8'); + // Restore the interpolation token which the template replaces with a + // static fallback title to avoid showing an unresolved template + // literal when served without interpolation (e.g. by the service worker) + map[languageCode] = readFileSync(indexHtmlPath, 'utf8').replace( + /