Skip to content

Commit e3b45df

Browse files
allow access the server router
1 parent 6d43e26 commit e3b45df

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-rest",
3-
"version": "2.2.5",
3+
"version": "2.2.6",
44
"description": "A Library to create RESTFul APIs with Typescript",
55
"author": "Thiago da Rosa de Bustamante <[email protected]>",
66
"keywords": [

src/server/server.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@ const serverDebugger = debug('typescript-rest:server:build');
1919
* The Http server main class.
2020
*/
2121
export class Server {
22-
23-
/**
24-
* Makes the server immutable. Any configuration change request to the Server
25-
* is ignored when immutable is true
26-
* @param value true to make immutable
27-
*/
28-
public static immutable(value: boolean) {
29-
Server.locked = value;
30-
}
31-
3222
/**
3323
* Create the routes for all classes decorated with our decorators
3424
*/
@@ -79,6 +69,30 @@ export class Server {
7969
}
8070
}
8171

72+
/**
73+
* Makes the server immutable. Any configuration change request to the Server
74+
* is ignored when immutable is true
75+
* @param value true to make immutable
76+
*/
77+
public static immutable(value: boolean) {
78+
Server.locked = value;
79+
}
80+
81+
/**
82+
* Return true if the server is immutable. Any configuration change request to the Server
83+
* is ignored when immutable is true
84+
*/
85+
public static isImmutable() {
86+
return Server.locked;
87+
}
88+
89+
/**
90+
* Retrieve the express router that serves the rest endpoints
91+
*/
92+
public static server() {
93+
return ServerContainer.get().router;
94+
}
95+
8296
/**
8397
* Return all paths accepted by the Server
8498
*/

test/unit/server.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ describe('Server', () => {
9494
Server.removeParameterConverter(null);
9595
Server.ignoreNextMiddlewares(false);
9696
expect(serverContainerStub.get).to.not.have.been.called;
97+
expect(Server.isImmutable()).to.be.true;
9798
});
9899

99100
});

0 commit comments

Comments
 (0)