forked from wbhob/nest-middlewares
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(connect-rid): add connect-rid middleware and respective types
- Loading branch information
Showing
9 changed files
with
106 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ConnectRidMiddleware } from './index'; | ||
import { expect } from 'chai'; | ||
|
||
describe('ConnectRidMiddleware', () => { | ||
let middleware: ConnectRidMiddleware; | ||
describe('properly configured', () => { | ||
beforeEach(() => { | ||
ConnectRidMiddleware.configure({}); | ||
middleware = new ConnectRidMiddleware(); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(middleware).to.not.be.undefined; | ||
}); | ||
|
||
it('should have a function called resolve', () => { | ||
expect(middleware.resolve).to.be.instanceof(Function); | ||
}); | ||
|
||
it('should should return a middleware from calling resolve', () => { | ||
expect(middleware.resolve()).to.be.an.instanceof(Function); | ||
}); | ||
afterEach(() => { | ||
ConnectRidMiddleware.configure(undefined); | ||
}); | ||
}); | ||
|
||
describe('not configured', () => { | ||
middleware = new ConnectRidMiddleware(); | ||
it('should should return a middleware from calling resolve', () => { | ||
expect(middleware.resolve()).to.be.an.instanceof(Function); | ||
}); | ||
}); | ||
}); |
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,24 @@ | ||
import * as rid from 'connect-rid'; | ||
|
||
import { Middleware, NestMiddleware } from '@nestjs/common'; | ||
|
||
import { RequestHandler } from 'express'; | ||
|
||
@Middleware() | ||
export class ConnectRidMiddleware implements NestMiddleware { | ||
|
||
// DELETE THESE LINES IF MIDDLEWARE DOES NOT TAKE OPTIONS | ||
public static configure(opts: rid.ConnectRidOptions) { | ||
this.options = opts; | ||
} | ||
|
||
private static options: rid.ConnectRidOptions; | ||
|
||
public resolve(...args: any[]) { | ||
if (ConnectRidMiddleware.options) { | ||
return rid(ConnectRidMiddleware.options); | ||
} else { | ||
return rid(); | ||
} | ||
} | ||
} |
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,31 @@ | ||
{ | ||
"name": "@nest-middlewares/connect-rid", | ||
"version": "1.0.0", | ||
"description": "NestJS middleware for Connect RID", | ||
"main": "index", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/wbhob/nest-middlewares.git" | ||
}, | ||
"keywords": [ | ||
"nest", | ||
"middlewares", | ||
"express", | ||
"node" | ||
], | ||
"author": "Wilson Hobbs <wilsonhobbs1@gmail.com>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/wbhob/nest-middlewares/issues" | ||
}, | ||
"homepage": "https://github.com/wbhob/nest-middlewares#readme", | ||
"peerDependencies": { | ||
"@nestjs/common": "^4.0.0" | ||
}, | ||
"dependencies": { | ||
"connect-rid": "0.0.1" | ||
} | ||
} |
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
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
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,10 @@ | ||
declare function rid(): void; | ||
declare function rid(opts: rid.ConnectRidOptions): void; | ||
|
||
declare namespace rid { | ||
export interface ConnectRidOptions { | ||
headerName?: string; | ||
} | ||
} | ||
|
||
export = rid; |