-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #373 from boostcampwm2023/BE-feature/profile-auth
Multer ๋์ ๋ฏธ๋ค์จ์ด๋ก ์ด๋
- Loading branch information
Showing
4 changed files
with
208 additions
and
154 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
nestjs-BE/server/src/common/middlewares/multer-file.middleware.ts
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Injectable, NestMiddleware } from '@nestjs/common'; | ||
import { Request, Response, NextFunction } from 'express'; | ||
import * as multer from 'multer'; | ||
|
||
export function MulterFileMiddleware(fieldName: string) { | ||
@Injectable() | ||
class MulterSingleMiddleware implements NestMiddleware { | ||
readonly multerInstance = multer(); | ||
|
||
use(req: Request, res: Response, next: NextFunction) { | ||
this.multerInstance.single(fieldName)(req, res, next); | ||
} | ||
} | ||
|
||
return MulterSingleMiddleware; | ||
} |
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,14 +1,29 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { | ||
MiddlewareConsumer, | ||
Module, | ||
NestModule, | ||
RequestMethod, | ||
} from '@nestjs/common'; | ||
import { SpacesService } from './spaces.service'; | ||
import { SpacesController } from './spaces.controller'; | ||
import { UploadModule } from '../upload/upload.module'; | ||
import { ProfileSpaceModule } from '../profile-space/profile-space.module'; | ||
import { AuthModule } from '../auth/auth.module'; | ||
import { MulterFileMiddleware } from '../common/middlewares/multer-file.middleware'; | ||
|
||
@Module({ | ||
imports: [ProfileSpaceModule, UploadModule, AuthModule], | ||
controllers: [SpacesController], | ||
providers: [SpacesService], | ||
exports: [SpacesService], | ||
}) | ||
export class SpacesModule {} | ||
export class SpacesModule implements NestModule { | ||
configure(consumer: MiddlewareConsumer) { | ||
consumer | ||
.apply(MulterFileMiddleware('icon')) | ||
.forRoutes( | ||
{ path: '/spaces', method: RequestMethod.POST }, | ||
{ path: '/spaces/:space_uuid', method: RequestMethod.PATCH }, | ||
); | ||
} | ||
} |
Oops, something went wrong.