File tree Expand file tree Collapse file tree 3 files changed +77
-0
lines changed Expand file tree Collapse file tree 3 files changed +77
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { CorsMiddleware } from './index' ;
2
+ import { expect } from 'chai' ;
3
+
4
+ describe ( 'CorsMiddleware' , ( ) => {
5
+ let middleware : CorsMiddleware ;
6
+
7
+ beforeEach ( ( ) => {
8
+ middleware = new CorsMiddleware ( ) ;
9
+ } ) ;
10
+
11
+ it ( 'should be defined' , ( ) => {
12
+ expect ( middleware ) . to . not . be . undefined ;
13
+ } ) ;
14
+
15
+ it ( 'should have a function called resolve' , ( ) => {
16
+ expect ( middleware . resolve ) . to . be . instanceof ( Function ) ;
17
+ } ) ;
18
+
19
+ it ( 'should should return a middleware from calling resolve' , ( ) => {
20
+ expect ( middleware . resolve ( ) ) . to . be . an . instanceof ( Function ) ;
21
+ } ) ;
22
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import * as cors from 'cors' ;
2
+
3
+ import { Middleware , NestMiddleware } from '@nestjs/common' ;
4
+
5
+ import { RequestHandler } from 'express' ;
6
+
7
+ @Middleware ( )
8
+ export class CorsMiddleware implements NestMiddleware {
9
+
10
+ public static configure ( opts : cors . CorsOptions ) {
11
+ this . options = opts ;
12
+ }
13
+
14
+ private static options : cors . CorsOptions ;
15
+
16
+
17
+ public resolve ( ...args : any [ ] ) {
18
+ if ( CorsMiddleware . options ) {
19
+ return cors ( CorsMiddleware . options ) ;
20
+ } else {
21
+ return cors ( ) ;
22
+ }
23
+ }
24
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " @nest-middlewares/cors" ,
3
+ "version" : " 1.0.0" ,
4
+ "description" : " NestJS middleware for Helmet" ,
5
+ "main" : " index" ,
6
+ "scripts" : {
7
+ "test" : " echo \" Error: no test specified\" && exit 1"
8
+ },
9
+ "repository" : {
10
+ "type" : " git" ,
11
+ "url" : " git+https://github.com/wbhob/nest-middlewares.git"
12
+ },
13
+ "keywords" : [
14
+ " nest" ,
15
+ " middlewares" ,
16
+ " express" ,
17
+ " node"
18
+ ],
19
+ "author" : " Wilson Hobbs <wilsonhobbs1@gmail.com>" ,
20
+ "license" : " MIT" ,
21
+ "bugs" : {
22
+ "url" : " https://github.com/wbhob/nest-middlewares/issues"
23
+ },
24
+ "homepage" : " https://github.com/wbhob/nest-middlewares#readme" ,
25
+ "dependencies" : {
26
+ "cors" : " ^2.8.4"
27
+ },
28
+ "peerDependencies" : {
29
+ "@nestjs/common" : " ^4.0.0"
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments