Skip to content

Commit

Permalink
Merge pull request #6 from getlarge/chore-setup-nestjs-devtools
Browse files Browse the repository at this point in the history
chore(cat-fostering-api): setup NestJS Devtools
  • Loading branch information
getlarge authored Aug 10, 2024
2 parents 99af446 + 95bfa73 commit f3d5f3b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
3 changes: 2 additions & 1 deletion apps/cat-fostering-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"nestjs-pino": "^4.0.0",
"typeorm": "^0.3.20",
"pg": "^8.11.5",
"validator": "13.11.0"
"validator": "13.11.0",
"@nestjs/devtools-integration": "0.1.6"
}
}
15 changes: 14 additions & 1 deletion apps/cat-fostering-api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { CatProfilesModule } from '@cat-fostering/nestjs-catprofile-module';
import { FosteringModule } from '@cat-fostering/nestjs-fostering-module';
import { UsersModule } from '@cat-fostering/nestjs-user-module';
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { ConditionalModule, ConfigModule, ConfigService } from '@nestjs/config';
import { DevtoolsModule } from '@nestjs/devtools-integration';
import { TypeOrmModule } from '@nestjs/typeorm';
import { LoggerModule } from 'nestjs-pino';
import path from 'node:path';
Expand All @@ -29,6 +30,18 @@ import {
)
),
}),
ConditionalModule.registerWhen(
DevtoolsModule.registerAsync({
inject: [ConfigService],
useFactory: (
configService: ConfigService<EnvironmentVariables, true>
) => ({
http: true,
port: configService.get('DEVTOOLS_PORT', { infer: true }),
}),
}),
(env: NodeJS.ProcessEnv) => env.NODE_ENV === 'development'
),
LoggerModule.forRoot({
pinoHttp: {
redact: [
Expand Down
10 changes: 10 additions & 0 deletions apps/cat-fostering-api/src/app/environment-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ export class EnvironmentVariables {
@IsNumber()
PORT?: number = 3000;

@Expose()
@IsString()
@IsOptional()
HOST?: string = '0.0.0.0';

@Expose()
@IsOptional()
@IsNumber()
DEVTOOLS_PORT?: number = 8000;

@Expose()
@IsUrl({
protocols: ['postgres', 'postgresql'],
Expand Down
4 changes: 3 additions & 1 deletion apps/cat-fostering-api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ async function bootstrap() {
{
logger: ['error', 'warn', 'log', 'debug', 'verbose'],
bufferLogs: true,
snapshot: true,
}
);
const configService =
Expand Down Expand Up @@ -94,7 +95,8 @@ async function bootstrap() {
SwaggerModule.setup('open-api', app, document, customOptions);

const port = configService.get('PORT', { infer: true });
await app.listen(port);
const host = configService.get('HOST', { infer: true });
await app.listen(port, host);
logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
);
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@nestjs/common": "^10.0.2",
"@nestjs/config": "^3.2.1",
"@nestjs/core": "^10.0.2",
"@nestjs/devtools-integration": "0.1.6",
"@nestjs/platform-express": "^10.0.2",
"@nestjs/swagger": "^7.3.1",
"@nestjs/typeorm": "^10.0.2",
Expand Down Expand Up @@ -73,13 +74,13 @@
"@nx-tools/nx-container": "^6.0.1",
"@nx/angular": "19.3.1",
"@nx/devkit": "19.3.1",
"@nx/playwright": "19.3.1",
"@nx/eslint": "19.3.1",
"@nx/eslint-plugin": "19.3.1",
"@nx/jest": "19.3.1",
"@nx/js": "19.3.1",
"@nx/nest": "19.3.1",
"@nx/node": "19.3.1",
"@nx/playwright": "19.3.1",
"@nx/web": "19.3.1",
"@nx/webpack": "19.3.1",
"@openapitools/openapi-generator-cli": "^2.13.4",
Expand Down

0 comments on commit f3d5f3b

Please sign in to comment.