-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: typeOrmConfig => config 로직 따라가기, multer 지금 안쓰니까 주석
- Loading branch information
1 parent
2bfa619
commit b65d49c
Showing
3 changed files
with
74 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
import { ConfigService } from '@nestjs/config'; | ||
import { MulterModuleAsyncOptions } from '@nestjs/platform-express'; | ||
import { diskStorage } from 'multer'; | ||
import { existsSync, mkdirSync } from 'fs'; | ||
import { extname } from 'path'; | ||
|
||
export const multerConfig: MulterModuleAsyncOptions = { | ||
inject: [ConfigService], | ||
useFactory: async (configService: ConfigService) => { | ||
return { | ||
storage: diskStorage({ | ||
destination: (req, file, callback) => { | ||
const uploadPath = '/app/dist/uploads'; | ||
if (!existsSync(uploadPath)) { | ||
// uploads 폴더가 존재하지 않을시, 생성합니다. | ||
mkdirSync(uploadPath); | ||
} | ||
callback(null, uploadPath); | ||
}, | ||
filename: (req, file, callback) => { | ||
const userAccessToken = 'test'; | ||
const extension = extname(file.originalname); | ||
callback(null, `${userAccessToken}-${file.fieldname}${extension}`); | ||
}, | ||
}), | ||
// limits: {}, | ||
// fileFilter(req, file, callback) {} | ||
}; | ||
}, | ||
}; | ||
// import { ConfigService } from '@nestjs/config'; | ||
// import { MulterModuleAsyncOptions } from '@nestjs/platform-express'; | ||
// import { diskStorage } from 'multer'; | ||
// import { existsSync, mkdirSync } from 'fs'; | ||
// import { extname } from 'path'; | ||
// | ||
// export const multerConfig: MulterModuleAsyncOptions = { | ||
// inject: [ConfigService], | ||
// useFactory: async (configService: ConfigService) => { | ||
// return { | ||
// storage: diskStorage({ | ||
// destination: (req, file, callback) => { | ||
// const uploadPath = '/app/dist/uploads'; | ||
// if (!existsSync(uploadPath)) { | ||
// // uploads 폴더가 존재하지 않을시, 생성합니다. | ||
// mkdirSync(uploadPath); | ||
// } | ||
// callback(null, uploadPath); | ||
// }, | ||
// filename: (req, file, callback) => { | ||
// const userAccessToken = 'test'; | ||
// const extension = extname(file.originalname); | ||
// callback(null, `${userAccessToken}-${file.fieldname}${extension}`); | ||
// }, | ||
// }), | ||
// // limits: {}, | ||
// // fileFilter(req, file, callback) {} | ||
// }; | ||
// }, | ||
// }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
import { ConfigService } from '@nestjs/config'; | ||
import { TypeOrmModuleAsyncOptions } from '@nestjs/typeorm'; | ||
import { registerAs } from '@nestjs/config'; | ||
import { z } from 'zod'; | ||
import * as process from 'process'; | ||
export default registerAs('typeorm', () => { | ||
const TYPE = 'postgres' as 'postgres'; | ||
const POSTGRES_HOST = z.string().parse(process.env.POSTGRES_HOST); | ||
const POSTGRES_PORT = z.string().parse(process.env.POSTGRES_PORT); | ||
const POSTGRES_USER = z.string().parse(process.env.POSTGRES_USER); | ||
const POSTGRES_PASSWORD = z.string().parse(process.env.POSTGRES_PASSWORD); | ||
const POSTGRES_DB = z.string().parse(process.env.POSTGRES_DB); | ||
const ENTITIES = [__dirname + '/../**/entities/*.entity.{js,ts}']; | ||
const SYNCHRONIZE: boolean = true; | ||
|
||
export const typeOrmConfig: TypeOrmModuleAsyncOptions = { | ||
inject: [ConfigService], | ||
useFactory: async (configService: ConfigService) => { | ||
return { | ||
type: 'postgres', | ||
host: configService.get<string>('POSTGRES_HOST'), | ||
port: configService.get<number>('POSTGRES_PORT'), | ||
username: configService.get<string>('POSTGRES_USER'), | ||
password: configService.get<string>('POSTGRES_PASSWORD'), | ||
database: configService.get<string>('POSTGRES_DB'), | ||
entities: [__dirname + '/../**/entities/*.entity.{js,ts}'], | ||
synchronize: true, | ||
}; | ||
}, | ||
}; | ||
return { | ||
TYPE, | ||
POSTGRES_HOST, | ||
POSTGRES_PORT, | ||
POSTGRES_USER, | ||
POSTGRES_PASSWORD, | ||
POSTGRES_DB, | ||
ENTITIES, | ||
SYNCHRONIZE, | ||
}; | ||
}); |