Skip to content

Commit

Permalink
serve .htaccess and .env
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirGer committed Mar 16, 2024
1 parent 31b6126 commit 08b190a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 26 deletions.
2 changes: 1 addition & 1 deletion charts/brokencrystals/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 0 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 0 additions & 6 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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: [
Expand Down
43 changes: 40 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -106,7 +143,7 @@ async function bootstrap() {
});
}

server.register(fastifyStatic, {
await server.register(fastifyStatic, {
root: join(__dirname, '..', 'client', 'build', 'vendor'),
prefix: `/vendor`,
decorateReply: false,
Expand Down

0 comments on commit 08b190a

Please sign in to comment.