Skip to content

Commit fbc756f

Browse files
authored
fix(common_files): serve .env and .htaccess files (#327)
1 parent e4aca6a commit fbc756f

7 files changed

Lines changed: 43 additions & 28 deletions

File tree

charts/brokencrystals/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: |
44
Benchmark application that uses modern technologies and implements a set of
55
common security vulnerabilities
66
type: application
7-
version: 0.0.61
7+
version: 0.0.62
88
keywords:
99
- brokencrystals
1010
- brkn

client/src/pages/marketplace/Marketplace.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const Marketplace: FC<Props> = (props: Props) => {
5454
? getLatestProducts().then((data) => setProducts(data))
5555
: getProducts(
5656
new Date(new Date().setFullYear(new Date().getFullYear() - 1)),
57-
new Date()
57+
new Date(new Date().setDate(new Date().getDate() + 1))
5858
).then((data) => setProducts(data));
5959
}, []);
6060

package-lock.json

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"@nestjs/graphql": "^11.0.0",
3737
"@nestjs/mercurius": "^11.0.3",
3838
"@nestjs/platform-fastify": "^9.3.9",
39-
"@nestjs/serve-static": "^4.0.1",
4039
"@nestjs/swagger": "^6.2.1",
4140
"@sectester/bus": "^0.16.5",
4241
"@sectester/core": "^0.16.5",

src/app.module.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import { HttpClientModule as HttpClientModule } from './httpclient/httpclient.mo
1313
import { TraceMiddleware } from './components/trace.middleware';
1414
import { GraphQLModule } from '@nestjs/graphql';
1515
import { MercuriusDriver, MercuriusDriverConfig } from '@nestjs/mercurius';
16-
import { ServeStaticModule } from '@nestjs/serve-static';
17-
import { join } from 'path';
1816
import { AppService } from './app.service';
1917
import { UsersService } from './users/users.service';
2018
import { AppResolver } from './app.resolver';
@@ -39,10 +37,6 @@ import { PartnersModule } from './partners/partners.module';
3937
graphiql: true,
4038
autoSchemaFile: true,
4139
}),
42-
ServeStaticModule.forRoot({
43-
rootPath: join(__dirname, '..', 'client', 'build'),
44-
serveStaticOptions: { dotfiles: 'allow' },
45-
}),
4640
],
4741
controllers: [AppController],
4842
providers: [

src/main.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import fastifyCookie from '@fastify/cookie';
66
import session from '@fastify/session';
77
import { GlobalExceptionFilter } from './components/global-exception.filter';
88
import * as os from 'os';
9-
import { readFileSync, readdirSync } from 'fs';
9+
import { readFileSync, readFile, readdirSync } from 'fs';
1010
import * as cluster from 'cluster';
1111
import {
1212
FastifyAdapter,
@@ -91,8 +91,45 @@ async function bootstrap() {
9191
: null,
9292
});
9393

94+
server.setDefaultRoute((req, res) => {
95+
if (req.url && req.url.startsWith('/api')) {
96+
res.statusCode = 404;
97+
return res.end({
98+
success: false,
99+
error: {
100+
kind: 'user_input',
101+
message: 'Not Found',
102+
},
103+
});
104+
}
105+
106+
readFile(
107+
join(__dirname, '..', 'client', 'build', 'index.html'),
108+
'utf8',
109+
(err, data) => {
110+
if (err) {
111+
res.statusCode = 500;
112+
res.end('Internal Server Error');
113+
return;
114+
}
115+
res.statusCode = 200;
116+
res.setHeader('Content-Type', 'text/html');
117+
res.end(data);
118+
},
119+
);
120+
});
121+
122+
await server.register(fastifyStatic, {
123+
root: join(__dirname, '..', 'client', 'build'),
124+
prefix: `/`,
125+
decorateReply: false,
126+
redirect: false,
127+
wildcard: false,
128+
serveDotFiles: true,
129+
});
130+
94131
for (const dir of readdirSync(join(__dirname, '..', 'client', 'vcs'))) {
95-
server.register(fastifyStatic, {
132+
await server.register(fastifyStatic, {
96133
root: join(__dirname, '..', 'client', 'vcs', dir),
97134
prefix: `/.${dir}`,
98135
decorateReply: false,
@@ -106,7 +143,7 @@ async function bootstrap() {
106143
});
107144
}
108145

109-
server.register(fastifyStatic, {
146+
await server.register(fastifyStatic, {
110147
root: join(__dirname, '..', 'client', 'build', 'vendor'),
111148
prefix: `/vendor`,
112149
decorateReply: false,

src/products/products.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class ProductsController {
7474
): Promise<ProductDto[]> {
7575
this.logger.debug('Get all products.');
7676
let df = new Date(new Date().setFullYear(new Date().getFullYear() - 1));
77-
let dt = new Date();
77+
let dt = new Date(new Date().setDate(new Date().getDate() + 1));
7878
if (dateFrom) {
7979
df = this.parseDate(dateFrom);
8080
}

0 commit comments

Comments
 (0)