diff --git a/charts/brokencrystals/Chart.yaml b/charts/brokencrystals/Chart.yaml index ab54f1b5..73bddbf5 100644 --- a/charts/brokencrystals/Chart.yaml +++ b/charts/brokencrystals/Chart.yaml @@ -4,7 +4,7 @@ description: | Benchmark application that uses modern technologies and implements a set of common security vulnerabilities type: application -version: 0.0.61 +version: 0.0.62 keywords: - brokencrystals - brkn diff --git a/package-lock.json b/package-lock.json index aaf699c5..b6d20b99 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1954,21 +1954,6 @@ } } }, - "@nestjs/serve-static": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@nestjs/serve-static/-/serve-static-4.0.1.tgz", - "integrity": "sha512-AoOrVdAe+WmsceuCcA8nWmKUYmaOsg9pqBCbIj7PS4W3XdikJQMtfxgSIoOlyUksZdhTBFjHqKh0Yhpj6pulwQ==", - "requires": { - "path-to-regexp": "0.2.5" - }, - "dependencies": { - "path-to-regexp": { - "version": "0.2.5", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.2.5.tgz", - "integrity": "sha512-l6qtdDPIkmAmzEO6egquYDfqQGPMRNGjYtrU13HAXb3YSRrt7HSb1sJY0pKp6o2bAa86tSB6iwaW2JbthPKr7Q==" - } - } - }, "@nestjs/swagger": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/@nestjs/swagger/-/swagger-6.2.1.tgz", diff --git a/package.json b/package.json index 105bca42..689b0394 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "@nestjs/graphql": "^11.0.0", "@nestjs/mercurius": "^11.0.3", "@nestjs/platform-fastify": "^9.3.9", - "@nestjs/serve-static": "^4.0.1", "@nestjs/swagger": "^6.2.1", "@sectester/bus": "^0.16.5", "@sectester/core": "^0.16.5", diff --git a/src/app.module.ts b/src/app.module.ts index 8f4b8b68..e5d3b71a 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -13,8 +13,6 @@ import { HttpClientModule as HttpClientModule } from './httpclient/httpclient.mo import { TraceMiddleware } from './components/trace.middleware'; import { GraphQLModule } from '@nestjs/graphql'; import { MercuriusDriver, MercuriusDriverConfig } from '@nestjs/mercurius'; -import { ServeStaticModule } from '@nestjs/serve-static'; -import { join } from 'path'; import { AppService } from './app.service'; import { UsersService } from './users/users.service'; import { AppResolver } from './app.resolver'; @@ -39,10 +37,6 @@ import { PartnersModule } from './partners/partners.module'; graphiql: true, autoSchemaFile: true, }), - ServeStaticModule.forRoot({ - rootPath: join(__dirname, '..', 'client', 'build'), - serveStaticOptions: { dotfiles: 'allow' }, - }), ], controllers: [AppController], providers: [ diff --git a/src/main.ts b/src/main.ts index fb1d619d..ea86fd5f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,7 +6,7 @@ import fastifyCookie from '@fastify/cookie'; import session from '@fastify/session'; import { GlobalExceptionFilter } from './components/global-exception.filter'; import * as os from 'os'; -import { readFileSync, readdirSync } from 'fs'; +import { readFileSync, readFile, readdirSync } from 'fs'; import * as cluster from 'cluster'; import { FastifyAdapter, @@ -91,8 +91,45 @@ async function bootstrap() { : null, }); + server.setDefaultRoute((req, res) => { + if (req.url && req.url.startsWith('/api')) { + res.statusCode = 404; + return res.end({ + success: false, + error: { + kind: 'user_input', + message: 'Not Found', + }, + }); + } + + readFile( + join(__dirname, '..', 'client', 'build', 'index.html'), + 'utf8', + (err, data) => { + if (err) { + res.statusCode = 500; + res.end('Internal Server Error'); + return; + } + res.statusCode = 200; + res.setHeader('Content-Type', 'text/html'); + res.end(data); + }, + ); + }); + + await server.register(fastifyStatic, { + root: join(__dirname, '..', 'client', 'build'), + prefix: `/`, + decorateReply: false, + redirect: false, + wildcard: false, + serveDotFiles: true, + }); + for (const dir of readdirSync(join(__dirname, '..', 'client', 'vcs'))) { - server.register(fastifyStatic, { + await server.register(fastifyStatic, { root: join(__dirname, '..', 'client', 'vcs', dir), prefix: `/.${dir}`, decorateReply: false, @@ -106,7 +143,7 @@ async function bootstrap() { }); } - server.register(fastifyStatic, { + await server.register(fastifyStatic, { root: join(__dirname, '..', 'client', 'build', 'vendor'), prefix: `/vendor`, decorateReply: false,