Skip to content

Commit

Permalink
fix(back): trust proxies, add status controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ebuildy committed Dec 9, 2022
1 parent 79456f8 commit 98f9072
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
25 changes: 25 additions & 0 deletions back/src/Status/status.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Controller, Get, RawBodyRequest, Req } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Request } from 'express';
import { getAppURL } from '../config/configuration';

@ApiTags('status')
@Controller('api/status')
export class StatusController {
@Get()
index(): any {
return 'ok';
}

@Get('/request')
request(@Req() req: RawBodyRequest<Request>): any {
return {
publicURL: getAppURL(),
protocol: req.protocol,
headers: req.headers,
baseUrl: req.baseUrl,
originalUrl: req.originalUrl,
signedCookies: req.signedCookies,
};
}
}
7 changes: 7 additions & 0 deletions back/src/Status/status.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { StatusController } from './status.controller';

@Module({
controllers: [StatusController],
})
export class StatusModule {}
2 changes: 2 additions & 0 deletions back/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AllExceptionsFilter } from './filters/catch-all.filter';
import { ServeStaticModule } from '@nestjs/serve-static';
import { SecurityModule } from './Security/security.module';
import { UrlGeneratorModule } from 'nestjs-url-generator';
import { StatusModule } from './Status/status.module';

@Module({
imports: [
Expand All @@ -19,6 +20,7 @@ import { UrlGeneratorModule } from 'nestjs-url-generator';
}),
StorageModule,
SecurityModule,
StatusModule,
/*ThrottlerModule.forRoot({
ttl: 10,
limit: 500,
Expand Down
5 changes: 4 additions & 1 deletion back/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { AppModule } from './app.module';

Expand All @@ -13,7 +14,7 @@ async function bootstrap() {
process.exit(1);
}

const app = await NestFactory.create(AppModule);
const app = await NestFactory.create<NestExpressApplication>(AppModule);

const config = new DocumentBuilder()
.setTitle('GUI')
Expand All @@ -32,6 +33,8 @@ async function bootstrap() {
)
.build();

app.set('trust proxy', 1);

const document = SwaggerModule.createDocument(app, config);

SwaggerModule.setup('api/console', app, document);
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ services:
- "80:80"

app:
#image: ghcr.io/datatok/gui:v0.3.2
build:
context: .
dockerfile: ./packages/docker/Dockerfile
Expand Down

0 comments on commit 98f9072

Please sign in to comment.