Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
feat(user): add configuration module
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed Jan 28, 2019
1 parent 28cca96 commit 13818bf
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
*.css.d.ts
*.css.d.ts
back/.env
8 changes: 8 additions & 0 deletions back/.env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
NODE_ENV=development
APP_SECRET=NotSoSecret

DB_HOST=localhost
DB_PORT=3306
DB_USER=admin
DB_PASSWORD=admin
DB_NAME=checkmoney
1 change: 1 addition & 0 deletions back/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@nestjs/common": "^5.6.2",
"@nestjs/core": "^5.6.2",
"@nestjs/swagger": "^2.5.1",
"@solid-soda/config": "^1.1.0",
"cors": "^2.8.5",
"reflect-metadata": "^0.1.13",
"rxjs": "^6.3.3"
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion back/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common'

import { ConfigModule } from './config/config.module'
import { MoneyModule } from './money/money.module'
import { UserModule } from './user/user.module'
import { UtilsModule } from './utils/utils.module'

@Module({
imports: [UserModule, MoneyModule, UtilsModule],
imports: [UserModule, MoneyModule, UtilsModule, ConfigModule],
})
export class AppModule implements NestModule {
public configure(consumer: MiddlewareConsumer) {
Expand Down
24 changes: 24 additions & 0 deletions back/src/config/ConfigationFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Provider } from '@nestjs/common'
import { DotEnvConfiguration, EnvConfiguration } from '@solid-soda/config'
import * as path from 'path'

import { Configuration } from './Configuration'

const isDev = () => process.env.NODE_ENV === 'development'

export default class ConfigurationFactory {
public static create(): Configuration {
if (isDev()) {
return new DotEnvConfiguration(path.resolve(__dirname, '../../.env'))
}

return new EnvConfiguration()
}

public static provider(): Provider {
return {
provide: Configuration,
useValue: ConfigurationFactory.create(),
}
}
}
1 change: 1 addition & 0 deletions back/src/config/Configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AbstractConfiguration as Configuration } from '@solid-soda/config'
11 changes: 11 additions & 0 deletions back/src/config/config.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common'

import ConfigurationFactory from './ConfigationFactory'

const configProvider = ConfigurationFactory.provider()

@Module({
providers: [configProvider],
exports: [configProvider],
})
export class ConfigModule {}
4 changes: 2 additions & 2 deletions back/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NestFactory } from '@nestjs/core'

import setupCors from '@back/addons/cors'
import setupSwagger from '@back/addons/swagger'
import { AppModule } from '@back/app.module'
import setupCors from '@back/config/cors'
import setupSwagger from '@back/config/swagger'

async function bootstrap() {
const app = await NestFactory.create(AppModule)
Expand Down
1 change: 1 addition & 0 deletions back/src/utils/utils.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ParseDateRangePipe } from './presentation/http/pipes/dateRange/ParseDat

@Module({
providers: [ParseDateRangePipe],
exports: [ParseDateRangePipe],
})
export class UtilsModule implements NestModule {
public configure(consumer: MiddlewareConsumer) {
Expand Down
Loading

0 comments on commit 13818bf

Please sign in to comment.