Skip to content

Commit

Permalink
fix: docker compose fixed, and remove http enable
Browse files Browse the repository at this point in the history
  • Loading branch information
andrechristikan committed Nov 10, 2024
1 parent b8cec83 commit 1096682
Show file tree
Hide file tree
Showing 18 changed files with 1,298 additions and 1,279 deletions.
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
APP_NAME=NestJS_ACK
APP_ENV=development
APP_ENV=local
APP_LANGUAGE=en
APP_TIMEZONE=Asia/Jakarta

HTTP_ENABLE=true
HTTP_HOST=localhost
HTTP_PORT=3000

DEBUG_ENABLE=false
DEBUG_ENABLE=true
DEBUG_LEVEL=debug

MIDDLEWARE_CORS_ORIGIN=*

URL_VERSIONING_ENABLE=true
URL_VERSION=1

DATABASE_URI=mongodb://localhost:27017,localhost:27018,localhost:27019/ack?retryWrites=true&w=majority&replicaSet=rs0
DATABASE_DEBUG=false
DATABASE_DEBUG=true

AUTH_JWT_ISSUER=https://example.com
AUTH_JWT_AUDIENCE=ack
Expand Down
16 changes: 15 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ version: '3.8'
name: ack

services:
service:
build:
context: .
container_name: service
hostname: service
ports:
- 3000:3000
volumes:
- ./src/:/app/src/
- .env/:/app/.env
restart: always
networks:
- app-network

redis:
image: redis:latest
container_name: redis
Expand Down Expand Up @@ -61,7 +75,7 @@ services:
extra_hosts:
- 'host.docker.internal:host-gateway'
healthcheck:
test: echo "try { rs.status() } catch (err) { rs.initiate({_id:'rs0',members:[{_id:0,host:'host.docker.internal:27017',priority:1},{_id:1,host:'host.docker.internal:27018',priority:0.5},{_id:2,host:'host.docker.internal:27019',priority:0.5}]}) }" | mongosh --bind_ip_all --port 27017 --replSet rs0doc --quiet
test: echo "try { rs.status() } catch (err) { rs.initiate({_id:'rs0',members:[{_id:0,host:'host.docker.internal:27017',priority:1},{_id:1,host:'host.docker.internal:27018',priority:0.5},{_id:2,host:'host.docker.internal:27019',priority:0.5}]}) }" | mongosh --bind_ip_all --port 27017 --quiet
interval: 5s
timeout: 30s
start_period: 0s
Expand Down
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ack-nestjs-boilerplate",
"version": "7.1.0",
"version": "7.1.1",
"description": "Ack NestJs Boilerplate",
"repository": {
"type": "git",
Expand Down Expand Up @@ -35,29 +35,29 @@
"remove": "nestjs-command remove:country && nestjs-command remove:apikey && nestjs-command remove:user && nestjs-command remove:role"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.685.0",
"@aws-sdk/client-ses": "^3.682.0",
"@aws-sdk/s3-request-presigner": "^3.685.0",
"@aws-sdk/client-s3": "^3.688.0",
"@aws-sdk/client-ses": "^3.687.0",
"@aws-sdk/s3-request-presigner": "^3.688.0",
"@casl/ability": "^6.7.2",
"@faker-js/faker": "^9.1.0",
"@nestjs/axios": "^3.1.1",
"@faker-js/faker": "^9.2.0",
"@nestjs/axios": "^3.1.2",
"@nestjs/bullmq": "^10.2.2",
"@nestjs/cache-manager": "^2.3.0",
"@nestjs/common": "^10.4.6",
"@nestjs/common": "^10.4.7",
"@nestjs/config": "^3.3.0",
"@nestjs/core": "^10.4.6",
"@nestjs/core": "^10.4.7",
"@nestjs/jwt": "^10.2.0",
"@nestjs/mongoose": "^10.1.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.4.6",
"@nestjs/swagger": "^8.0.1",
"@nestjs/platform-express": "^10.4.7",
"@nestjs/swagger": "^8.0.5",
"@nestjs/terminus": "^10.2.3",
"@nestjs/throttler": "^6.2.1",
"@sentry/nestjs": "^8.36.0",
"@sentry/profiling-node": "^8.36.0",
"@sentry/nestjs": "^8.37.1",
"@sentry/profiling-node": "^8.37.1",
"axios": "^1.7.7",
"bcryptjs": "^2.4.3",
"bullmq": "^5.23.0",
"bullmq": "^5.25.4",
"cache-manager": "^4.1.0",
"cache-manager-redis-store": "^3.0.1",
"case": "^1.6.3",
Expand All @@ -68,15 +68,15 @@
"google-auth-library": "^9.14.2",
"helmet": "^8.0.0",
"luxon": "^3.5.0",
"mongoose": "^8.8.0",
"mongoose": "^8.8.1",
"nestjs-command": "^3.1.4",
"nestjs-i18n": "^10.4.9",
"nestjs-pino": "^4.1.0",
"passport": "^0.7.0",
"passport-headerapikey": "^1.2.2",
"passport-jwt": "^4.0.1",
"pino-http": "^10.3.0",
"pino-pretty": "^11.3.0",
"pino-pretty": "^12.1.0",
"reflect-metadata": "^0.2.2",
"response-time": "^2.3.3",
"rxjs": "^7.8.1",
Expand All @@ -89,12 +89,12 @@
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@eslint/js": "^9.14.0",
"@golevelup/ts-jest": "^0.5.6",
"@nestjs/cli": "^10.4.5",
"@golevelup/ts-jest": "^0.6.0",
"@nestjs/cli": "^10.4.7",
"@nestjs/schematics": "^10.2.3",
"@nestjs/testing": "^10.4.6",
"@nestjs/testing": "^10.4.7",
"@swc/cli": "^0.5.0",
"@swc/core": "^1.7.42",
"@swc/core": "^1.9.1",
"@swc/jest": "^0.2.37",
"@types/bcryptjs": "^2.4.6",
"@types/bytes": "^3.1.4",
Expand All @@ -108,12 +108,12 @@
"@types/luxon": "^3.4.2",
"@types/ms": "^0.7.34",
"@types/multer": "^1.4.12",
"@types/node": "^22.8.7",
"@types/node": "^22.9.0",
"@types/passport-jwt": "^4.0.1",
"@types/response-time": "^2.3.8",
"@types/supertest": "^6.0.2",
"@types/uuid": "^10.0.0",
"cspell": "^8.15.6",
"cspell": "^8.16.0",
"eslint": "^9.14.0",
"eslint-config-prettier": "^9.1.0",
"husky": "^9.1.6",
Expand All @@ -129,7 +129,7 @@
"ts-prune": "^0.10.3",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.6.3",
"typescript-eslint": "^8.12.2"
"typescript-eslint": "^8.13.0"
},
"lint-staged": {
"**/*.ts": [
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { WorkerModule } from 'src/worker/worker.module';
AppMiddlewareModule,

// Routes
RouterModule.forRoot(),
RouterModule,

// Workers
WorkerModule,
Expand Down
19 changes: 18 additions & 1 deletion src/app/dtos/app.env.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
IsOptional,
IsString,
IsUrl,
MinLength,
} from 'class-validator';
import {
ENUM_APP_ENVIRONMENT,
Expand All @@ -17,10 +18,12 @@ import { ENUM_MESSAGE_LANGUAGE } from 'src/common/message/enums/message.enum';
export class AppEnvDto {
@IsString()
@IsNotEmpty()
@MinLength(1)
APP_NAME: string;

@IsString()
@IsNotEmpty()
@MinLength(1)
@IsEnum(ENUM_APP_ENVIRONMENT)
APP_ENV: ENUM_APP_ENVIRONMENT;

Expand All @@ -36,6 +39,7 @@ export class AppEnvDto {

@IsNotEmpty()
@IsString()
@MinLength(1)
HTTP_HOST: string;

@IsNumber()
Expand All @@ -50,6 +54,12 @@ export class AppEnvDto {

@IsString()
@IsNotEmpty()
@MinLength(1)
DEBUG_LEVEL: string;

@IsString()
@IsNotEmpty()
@MinLength(1)
MIDDLEWARE_CORS_ORIGIN: string;

@IsBoolean()
Expand All @@ -64,7 +74,8 @@ export class AppEnvDto {

@IsNotEmpty()
@IsString()
DATABASE_URI: string;
@MinLength(1)
DATABASE_URL: string;

@IsBoolean()
@IsNotEmpty()
Expand All @@ -73,26 +84,32 @@ export class AppEnvDto {

@IsNotEmpty()
@IsString()
@MinLength(1)
AUTH_JWT_AUDIENCE: string;

@IsNotEmpty()
@IsString()
@MinLength(1)
AUTH_JWT_ISSUER: string;

@IsNotEmpty()
@IsString()
@MinLength(1)
AUTH_JWT_ACCESS_TOKEN_EXPIRED: string;

@IsNotEmpty()
@IsString()
@MinLength(1)
AUTH_JWT_ACCESS_TOKEN_SECRET_KEY: string;

@IsNotEmpty()
@IsString()
@MinLength(1)
AUTH_JWT_REFRESH_TOKEN_EXPIRED: string;

@IsNotEmpty()
@IsString()
@MinLength(1)
AUTH_JWT_REFRESH_TOKEN_SECRET_KEY: string;

@IsOptional()
Expand Down
18 changes: 4 additions & 14 deletions src/app/filters/app.http.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import { HttpArgumentsHost } from '@nestjs/common/interfaces';
import { ConfigService } from '@nestjs/config';
import { Response } from 'express';
import { ENUM_APP_ENVIRONMENT } from 'src/app/enums/app.enum';
import { IAppException } from 'src/app/interfaces/app.interface';
import { HelperDateService } from 'src/common/helper/services/helper.date.service';
import { ENUM_MESSAGE_LANGUAGE } from 'src/common/message/enums/message.enum';
Expand All @@ -24,7 +23,6 @@ export class AppHttpFilter implements ExceptionFilter {

private readonly globalPrefix: string;
private readonly docPrefix: string;
private readonly env: ENUM_APP_ENVIRONMENT;

constructor(
private readonly messageService: MessageService,
Expand All @@ -33,7 +31,6 @@ export class AppHttpFilter implements ExceptionFilter {
) {
this.globalPrefix = this.configService.get<string>('app.globalPrefix');
this.docPrefix = this.configService.get<string>('doc.prefix');
this.env = this.configService.get<ENUM_APP_ENVIRONMENT>('app.env');
}

async catch(exception: HttpException, host: ArgumentsHost): Promise<void> {
Expand All @@ -47,17 +44,10 @@ export class AppHttpFilter implements ExceptionFilter {
!request.path.startsWith(this.globalPrefix) &&
!request.path.startsWith(this.docPrefix)
) {
if (this.env === ENUM_APP_ENVIRONMENT.PRODUCTION) {
response.redirect(
HttpStatus.PERMANENT_REDIRECT,
'/api/public/hello'
);
} else {
response.redirect(
HttpStatus.PERMANENT_REDIRECT,
this.docPrefix
);
}
response.redirect(
HttpStatus.PERMANENT_REDIRECT,
'/api/public/hello'
);

return;
}
Expand Down
3 changes: 0 additions & 3 deletions src/app/middlewares/app.cors.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ import { HttpStatus, Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';
import cors, { CorsOptions } from 'cors';
import { ConfigService } from '@nestjs/config';
import { ENUM_APP_ENVIRONMENT } from 'src/app/enums/app.enum';

@Injectable()
export class AppCorsMiddleware implements NestMiddleware {
private readonly appEnv: ENUM_APP_ENVIRONMENT;
private readonly allowOrigin: string | boolean | string[];
private readonly allowMethod: string[];
private readonly allowHeader: string[];

constructor(private readonly configService: ConfigService) {
this.appEnv = this.configService.get<ENUM_APP_ENVIRONMENT>('app.env');
this.allowOrigin = this.configService.get<string | boolean | string[]>(
'middleware.cors.allowOrigin'
);
Expand Down
5 changes: 0 additions & 5 deletions src/app/middlewares/app.url-version.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { Injectable, NestMiddleware } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Response, NextFunction } from 'express';
import { ENUM_APP_ENVIRONMENT } from 'src/app/enums/app.enum';
import { IRequestApp } from 'src/common/request/interfaces/request.interface';

@Injectable()
export class AppUrlVersionMiddleware implements NestMiddleware {
private readonly env: ENUM_APP_ENVIRONMENT;

private readonly globalPrefix: string;

private readonly urlVersionEnable: boolean;
private readonly urlVersionPrefix: string;
private readonly urlVersion: string;

constructor(private readonly configService: ConfigService) {
this.env = this.configService.get<ENUM_APP_ENVIRONMENT>('app.env');

this.globalPrefix = this.configService.get<string>('app.globalPrefix');
this.urlVersionEnable = this.configService.get<boolean>(
'app.urlVersion.enable'
Expand Down
5 changes: 3 additions & 2 deletions src/common/database/services/database.options.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class DatabaseOptionService implements IDatabaseOptionService {
createOptions(): MongooseModuleOptions {
const env = this.configService.get<string>('app.env');

const uri = this.configService.get<string>('database.uri');
const url = this.configService.get<string>('database.url');
const debug = this.configService.get<boolean>('database.debug');

const timeoutOptions = this.configService.get<Record<string, number>>(
Expand All @@ -24,11 +24,12 @@ export class DatabaseOptionService implements IDatabaseOptionService {
}

const mongooseOptions: MongooseModuleOptions = {
uri,
uri: url,
autoCreate: env === ENUM_APP_ENVIRONMENT.MIGRATION,
autoIndex: env === ENUM_APP_ENVIRONMENT.MIGRATION,
...timeoutOptions,
};
console.log('mongooseOptions', mongooseOptions);

return mongooseOptions;
}
Expand Down
Loading

0 comments on commit 1096682

Please sign in to comment.