Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^7.4.2",
"@nestjs/common": "^7.6.5",
"@nestjs/config": "^0.5.0",
"@nestjs/core": "^7.4.2",
"@nestjs/jwt": "^7.1.0",
Expand All @@ -32,6 +32,7 @@
"@nestjs/websockets": "^7.4.2",
"@prisma/client": "2.12.1",
"bcryptjs": "^2.4.3",
"cache-manager": "^3.4.0",
"class-transformer": "^0.3.1",
"class-validator": "^0.12.2",
"fs-extra": "^9.0.1",
Expand All @@ -54,6 +55,7 @@
"@nestjs/testing": "^7.4.2",
"@prisma/cli": "2.12.1",
"@types/bcryptjs": "^2.4.2",
"@types/cache-manager": "^2.10.3",
"@types/express": "^4.17.7",
"@types/jest": "26.0.14",
"@types/node": "^14.0.27",
Expand Down
9 changes: 7 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Module } from '@nestjs/common';
import { CacheInterceptor, CacheModule, Module } from '@nestjs/common';
import { AuthModule } from './auth/auth.module';
import { UsersModule } from './users/users.module';
import { BuildsModule } from './builds/builds.module';
Expand All @@ -7,12 +7,13 @@ import { TestRunsModule } from './test-runs/test-runs.module';
import { TestVariationsModule } from './test-variations/test-variations.module';
import { PrismaService } from './prisma/prisma.service';
import { ConfigModule } from '@nestjs/config';
import { APP_FILTER } from '@nestjs/core';
import { APP_FILTER, APP_INTERCEPTOR } from '@nestjs/core';
import { HttpExceptionFilter } from './http-exception.filter';

@Module({
imports: [
ConfigModule.forRoot({ isGlobal: true }),
CacheModule.register(),
AuthModule,
UsersModule,
BuildsModule,
Expand All @@ -26,6 +27,10 @@ import { HttpExceptionFilter } from './http-exception.filter';
provide: APP_FILTER,
useClass: HttpExceptionFilter,
},
{
provide: APP_INTERCEPTOR,
useClass: CacheInterceptor,
},
],
})
export class AppModule {}
8 changes: 6 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { join } from 'path';
import * as bodyParser from 'body-parser';
import { readFileSync, existsSync } from 'fs';
import { HttpsOptions } from '@nestjs/common/interfaces/external/https-options.interface';
import { IMAGE_PATH } from './shared/static/static.service';
import { NestExpressApplication } from '@nestjs/platform-express';

function getHttpsOptions(): HttpsOptions | null {
const keyPath = './secrets/ssl.key';
Expand All @@ -22,7 +24,7 @@ function getHttpsOptions(): HttpsOptions | null {
}

async function bootstrap() {
const app = await NestFactory.create(AppModule, {
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
cors: true,
httpsOptions: getHttpsOptions(),
});
Expand All @@ -34,7 +36,9 @@ async function bootstrap() {
}

// serve images
app.use(express.static(join(process.cwd(), 'imageUploads/')));
app.useStaticAssets(join(process.cwd(), IMAGE_PATH), {
maxAge: 31536000
});

await app.listen(process.env.APP_PORT || 3000);
}
Expand Down
7 changes: 4 additions & 3 deletions src/shared/static/static.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import path from 'path';
import { writeFileSync, readFileSync, unlink, mkdirSync, existsSync } from 'fs';
import { PNG, PNGWithMetadata } from 'pngjs';

export const IMAGE_PATH = 'imageUploads/'

@Injectable()
export class StaticService {
saveImage(type: 'screenshot' | 'diff' | 'baseline', imageBuffer: Buffer): string {
Expand Down Expand Up @@ -35,9 +37,8 @@ export class StaticService {
}

private getImagePath(imageName: string): string {
const dir = 'imageUploads/';
this.ensureDirectoryExistence(dir);
return path.resolve(dir, imageName);
this.ensureDirectoryExistence(IMAGE_PATH);
return path.resolve(IMAGE_PATH, imageName);
}

private ensureDirectoryExistence(dir: string) {
Expand Down