Browse Source

Improve redirection of home page

pull/2156/head
Thomas 2 years ago
parent
commit
c2f4d9223e
  1. 29
      apps/api/src/app/app.module.ts
  2. 10
      libs/common/src/lib/config.ts

29
apps/api/src/app/app.module.ts

@ -35,6 +35,11 @@ import { RedisCacheModule } from './redis-cache/redis-cache.module';
import { SubscriptionModule } from './subscription/subscription.module';
import { SymbolModule } from './symbol/symbol.module';
import { UserModule } from './user/user.module';
import {
DEFAULT_LANGUAGE_CODE,
SUPPORTED_LANGUAGE_CODES
} from '@ghostfolio/common/config';
import { StatusCodes } from 'http-status-codes';
@Module({
imports: [
@ -71,14 +76,24 @@ import { UserModule } from './user/user.module';
ScheduleModule.forRoot(),
ServeStaticModule.forRoot({
serveStaticOptions: {
/*etag: false // Disable etag header to fix PWA
setHeaders: (res, path) => {
if (path.includes('ngsw.json')) {
// Disable cache (https://stackoverflow.com/questions/22632593/how-to-disable-webpage-caching-in-expressjs-nodejs/39775595)
// https://gertjans.home.xs4all.nl/javascript/cache-control.html#no-cache
res.set('Cache-Control', 'no-cache, no-store, must-revalidate');
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.includes(code)) {
languageCode = code;
}
} catch {}
res.set('Location', `/${languageCode}`);
res.statusCode = StatusCodes.MOVED_PERMANENTLY;
}
}
}*/
},
rootPath: join(__dirname, '..', 'client'),
exclude: ['/api*']

10
libs/common/src/lib/config.ts

@ -91,4 +91,14 @@ export const QUEUE_JOB_STATUS_LIST = <JobStatus[]>[
'waiting'
];
export const SUPPORTED_LANGUAGE_CODES = [
'de',
'en',
'es',
'fr',
'it',
'nl',
'pt'
];
export const UNKNOWN_KEY = 'UNKNOWN';

Loading…
Cancel
Save