feat: init project.
This commit is contained in:
7
src/commons/middleware/parse-body.middleware.spec.ts
Normal file
7
src/commons/middleware/parse-body.middleware.spec.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { ParseBodyMiddleware } from './parse-body.middleware';
|
||||
|
||||
describe('ParseBodyMiddleware', () => {
|
||||
it('should be defined', () => {
|
||||
expect(new ParseBodyMiddleware()).toBeDefined();
|
||||
});
|
||||
});
|
13
src/commons/middleware/parse-body.middleware.ts
Normal file
13
src/commons/middleware/parse-body.middleware.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Injectable, NestMiddleware } from '@nestjs/common';
|
||||
import { json, urlencoded, text } from 'body-parser';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
|
||||
@Injectable()
|
||||
export class ParseBodyMiddleware implements NestMiddleware {
|
||||
use(req: Request, res: Response, next: NextFunction) {
|
||||
json()(req, res, () =>
|
||||
urlencoded()(req, res, () => text()(req, res, next)),
|
||||
);
|
||||
// next();
|
||||
}
|
||||
}
|
7
src/commons/middleware/raw-body.middleware.spec.ts
Normal file
7
src/commons/middleware/raw-body.middleware.spec.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { RawBodyMiddleware } from './raw-body.middleware';
|
||||
|
||||
describe('RawBodyMiddleware', () => {
|
||||
it('should be defined', () => {
|
||||
expect(new RawBodyMiddleware()).toBeDefined();
|
||||
});
|
||||
});
|
10
src/commons/middleware/raw-body.middleware.ts
Normal file
10
src/commons/middleware/raw-body.middleware.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Injectable, NestMiddleware } from '@nestjs/common';
|
||||
import { raw } from 'body-parser';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
|
||||
@Injectable()
|
||||
export class RawBodyMiddleware implements NestMiddleware {
|
||||
use(req: Request, res: Response, next: NextFunction) {
|
||||
raw({ type: '*/*' })(req, res, next);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user