|
1 | | -import { Module } from "@nestjs/common"; |
2 | | -import { ConfigModule, ConfigService } from "@nestjs/config"; |
3 | | -import { CacheModule } from "@nestjs/cache-manager"; |
4 | | -import { createKeyv, Keyv } from "@keyv/redis"; |
5 | | -import { CacheableMemory } from "cacheable"; |
6 | | -import Joi from "joi"; |
| 1 | +import { Module } from '@nestjs/common'; |
| 2 | +import { ConfigModule, ConfigService } from '@nestjs/config'; |
| 3 | +import { CacheModule } from '@nestjs/cache-manager'; |
| 4 | +import { createKeyv, Keyv } from '@keyv/redis'; |
| 5 | +import { CacheableMemory } from 'cacheable'; |
| 6 | +import Joi from 'joi'; |
7 | 7 |
|
8 | | -import configs from "./config"; |
| 8 | +import configs from './config'; |
9 | 9 |
|
10 | 10 | @Module({ |
11 | | - imports: [ |
12 | | - ConfigModule.forRoot({ |
13 | | - load: configs, |
14 | | - isGlobal: true, |
15 | | - cache: true, |
16 | | - envFilePath: [".env.docker", ".env"], |
17 | | - expandVariables: true, |
18 | | - validationSchema: Joi.object({ |
19 | | - // App |
20 | | - NODE_ENV: Joi.string() |
21 | | - .valid("development", "staging", "production", "local") |
22 | | - .default("development"), |
23 | | - APP_NAME: Joi.string().default("post-worker"), |
24 | | - APP_DEBUG: Joi.boolean().truthy("true").falsy("false").default(false), |
| 11 | + imports: [ |
| 12 | + ConfigModule.forRoot({ |
| 13 | + load: configs, |
| 14 | + isGlobal: true, |
| 15 | + cache: true, |
| 16 | + envFilePath: ['.env'], |
| 17 | + expandVariables: true, |
| 18 | + validationSchema: Joi.object({ |
| 19 | + // App |
| 20 | + NODE_ENV: Joi.string() |
| 21 | + .valid('development', 'staging', 'production', 'local') |
| 22 | + .default('development'), |
| 23 | + APP_NAME: Joi.string().default('post-worker'), |
| 24 | + APP_DEBUG: Joi.boolean().truthy('true').falsy('false').default(false), |
25 | 25 |
|
26 | | - // Database |
27 | | - DATABASE_URL: Joi.string().uri().required(), |
| 26 | + // Database |
| 27 | + DATABASE_URL: Joi.string().uri().required(), |
28 | 28 |
|
29 | | - // Redis |
30 | | - REDIS_URL: Joi.string().uri().default("redis://localhost:6379"), |
31 | | - REDIS_KEY_PREFIX: Joi.string().default("post-worker:"), |
32 | | - REDIS_TTL: Joi.number().default(3600), |
| 29 | + // Redis |
| 30 | + REDIS_URL: Joi.string().uri().default('redis://localhost:6379'), |
| 31 | + REDIS_KEY_PREFIX: Joi.string().default('post-worker:'), |
| 32 | + REDIS_TTL: Joi.number().default(3600), |
33 | 33 |
|
34 | | - // RabbitMQ |
35 | | - RABBITMQ_URL: Joi.string().required(), |
36 | | - RABBITMQ_QUEUE: Joi.string().default("post_worker_queue"), |
37 | | - }), |
38 | | - }), |
39 | | - |
40 | | - CacheModule.registerAsync({ |
41 | | - inject: [ConfigService], |
42 | | - useFactory: async (configService: ConfigService) => { |
43 | | - const ttl = configService.get<number>("redis.ttl") * 1000; |
44 | | - const redisUrl = configService.get<string>("redis.url"); |
45 | | - return { |
46 | | - stores: [ |
47 | | - new Keyv({ |
48 | | - store: new CacheableMemory({ ttl, lruSize: 1000 }), |
| 34 | + // RabbitMQ |
| 35 | + RABBITMQ_URL: Joi.string().required(), |
| 36 | + RABBITMQ_QUEUE: Joi.string().default('post_worker_queue'), |
49 | 37 | }), |
50 | | - createKeyv(redisUrl), |
51 | | - ], |
52 | | - }; |
53 | | - }, |
54 | | - isGlobal: true, |
55 | | - }), |
56 | | - ], |
57 | | - exports: [], |
| 38 | + }), |
| 39 | + |
| 40 | + CacheModule.registerAsync({ |
| 41 | + inject: [ConfigService], |
| 42 | + useFactory: async (configService: ConfigService) => { |
| 43 | + const ttl = configService.get<number>('redis.ttl') * 1000; |
| 44 | + const redisUrl = configService.get<string>('redis.url'); |
| 45 | + return { |
| 46 | + stores: [ |
| 47 | + new Keyv({ |
| 48 | + store: new CacheableMemory({ ttl, lruSize: 1000 }), |
| 49 | + }), |
| 50 | + createKeyv(redisUrl), |
| 51 | + ], |
| 52 | + }; |
| 53 | + }, |
| 54 | + isGlobal: true, |
| 55 | + }), |
| 56 | + ], |
| 57 | + exports: [], |
58 | 58 | }) |
59 | 59 | export class CommonModule {} |
0 commit comments