diff --git a/CHANGELOG.md b/CHANGELOG.md index e20e6d32..a0d2e8f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## 1.179.4 - 13.08.2022 +## 1.179.5 - 15.08.2022 ### Added diff --git a/angular.json b/angular.json index 8ee42869..632049b7 100644 --- a/angular.json +++ b/angular.json @@ -87,11 +87,6 @@ "input": "", "output": "./../assets" }, - { - "glob": "index.html", - "input": "apps/client/src/assets", - "output": "./../" - }, { "glob": "LICENSE", "input": "", diff --git a/apps/api/src/app/app.module.ts b/apps/api/src/app/app.module.ts index f1fc2797..e41b60b0 100644 --- a/apps/api/src/app/app.module.ts +++ b/apps/api/src/app/app.module.ts @@ -10,7 +10,7 @@ import { ExchangeRateDataModule } from '@ghostfolio/api/services/exchange-rate-d import { PrismaModule } from '@ghostfolio/api/services/prisma.module'; import { TwitterBotModule } from '@ghostfolio/api/services/twitter-bot/twitter-bot.module'; import { BullModule } from '@nestjs/bull'; -import { Module } from '@nestjs/common'; +import { MiddlewareConsumer, Module, RequestMethod } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { ScheduleModule } from '@nestjs/schedule'; import { ServeStaticModule } from '@nestjs/serve-static'; @@ -23,6 +23,7 @@ import { AuthModule } from './auth/auth.module'; import { BenchmarkModule } from './benchmark/benchmark.module'; import { CacheModule } from './cache/cache.module'; import { ExportModule } from './export/export.module'; +import { FrontendMiddleware } from './frontend.middleware'; import { ImportModule } from './import/import.module'; import { InfoModule } from './info/info.module'; import { OrderModule } from './order/order.module'; @@ -82,4 +83,10 @@ import { UserModule } from './user/user.module'; controllers: [AppController], providers: [CronService] }) -export class AppModule {} +export class AppModule { + configure(consumer: MiddlewareConsumer) { + consumer + .apply(FrontendMiddleware) + .forRoutes({ path: '*', method: RequestMethod.ALL }); + } +} diff --git a/apps/api/src/app/frontend.middleware.ts b/apps/api/src/app/frontend.middleware.ts new file mode 100644 index 00000000..ffb3fd13 --- /dev/null +++ b/apps/api/src/app/frontend.middleware.ts @@ -0,0 +1,33 @@ +import * as path from 'path'; + +import { DEFAULT_LANGUAGE_CODE } from '@ghostfolio/common/config'; +import { Injectable, NestMiddleware } from '@nestjs/common'; +import { NextFunction, Request, Response } from 'express'; + +@Injectable() +export class FrontendMiddleware implements NestMiddleware { + use(req: Request, res: Response, next: NextFunction) { + if (req.path.startsWith('/api/') || this.isFileRequest(req.url)) { + // Skip + next(); + } else { + res.sendFile( + path.join( + __dirname, + '..', + 'client', + DEFAULT_LANGUAGE_CODE, + 'index.html' + ) + ); + } + } + + private isFileRequest(filename: string) { + if (filename.includes('auth/ey')) { + return false; + } + + return filename.split('.').pop() !== filename; + } +} diff --git a/apps/client/src/assets/index.html b/apps/client/src/assets/index.html deleted file mode 100644 index 051550fd..00000000 --- a/apps/client/src/assets/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - Ghostfol.io - - - - - - diff --git a/package.json b/package.json index dc476f1d..8535a07f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ghostfolio", - "version": "1.179.4", + "version": "1.179.5", "homepage": "https://ghostfol.io", "license": "AGPL-3.0", "scripts": {