Skip to content

Commit 59f5972

Browse files
“lragji”“lragji”
“lragji”
authored and
“lragji”
committed
Fixed bug which overwrote global handlers
1 parent 6ab9730 commit 59f5972

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ async function AppStartUp(rootRouter, DIContainer, application) {
5353
.get("/", (req, res) => {
5454
res.send(req.DIProp.fetchInstance("msg").message);
5555
})
56+
.post("/", (req, res) => {
57+
console.log(req.body);
58+
})
5659
.get("/error", (req, res) => {
5760
throw new Error("This is an error to validate final 'ErrorResponseTransformer' error handling of library");
5861
});
@@ -64,8 +67,8 @@ async function AppStartUp(rootRouter, DIContainer, application) {
6467
.registerApplicationHandler(utilities.helmetMiddleware(), "*", 1, ApplicationTypes.Both) //register helmet middleware for both application and health
6568
.registerApplicationHandler(utilities.bodyParserURLEncodingMiddleware(), "*", 2, ApplicationTypes.Main) //register body parser url middleware for application
6669
.registerApplicationHandler(utilities.bodyParserJSONEncodingMiddleware({ limit: '50M' }), "*", 3, ApplicationTypes.Main) //register body parser json middleware for application
67-
.registerApplicationHandler(apiDocs.router, apiDocs.hostingPath, 3, ApplicationTypes.Main) //register api docs
68-
.registerApplicationHandler(utilities.injectInRequestMiddleware("DIProp", DIContainer), "*", 4, ApplicationTypes.Main) //register DI container middleware
70+
.registerApplicationHandler(apiDocs.router, apiDocs.hostingPath, 4, ApplicationTypes.Main) //register api docs
71+
.registerApplicationHandler(utilities.injectInRequestMiddleware("DIProp", DIContainer), "*", 6, ApplicationTypes.Main) //register DI container middleware
6972
.overrideCatchAllErrorResponseTransformer((req, error) => ({ //override the default catch all error response transformer
7073
path: req.path,
7174
status: 500,

examples/simple-express/index.mjs

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ async function AppStartUp(rootRouter, DIContainer, application) {
1616
.get("/", (req, res) => {
1717
res.send(req.DIProp.fetchInstance("msg").message);
1818
})
19+
.post("/", (req, res) => {
20+
console.log(req.body);
21+
})
1922
.get("/error", (req, res) => {
2023
throw new Error("This is an error to validate final 'ErrorResponseTransformer' error handling of library");
2124
});
@@ -27,8 +30,8 @@ async function AppStartUp(rootRouter, DIContainer, application) {
2730
.registerApplicationHandler(utilities.helmetMiddleware(), "*", 1, ApplicationTypes.Both) //register helmet middleware for both application and health
2831
.registerApplicationHandler(utilities.bodyParserURLEncodingMiddleware(), "*", 2, ApplicationTypes.Main) //register body parser url middleware for application
2932
.registerApplicationHandler(utilities.bodyParserJSONEncodingMiddleware({ limit: '50M' }), "*", 3, ApplicationTypes.Main) //register body parser json middleware for application
30-
.registerApplicationHandler(apiDocs.router, apiDocs.hostingPath, 3, ApplicationTypes.Main) //register api docs
31-
.registerApplicationHandler(utilities.injectInRequestMiddleware("DIProp", DIContainer), "*", 4, ApplicationTypes.Main) //register DI container middleware
33+
.registerApplicationHandler(apiDocs.router, apiDocs.hostingPath, 4, ApplicationTypes.Main) //register api docs
34+
.registerApplicationHandler(utilities.injectInRequestMiddleware("DIProp", DIContainer), "*", 5, ApplicationTypes.Main) //register DI container middleware
3235
.overrideCatchAllErrorResponseTransformer((req, error) => ({ //override the default catch all error response transformer
3336
path: req.path,
3437
status: 500,

src/application-builder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ export class ApplicationBuilder {
347347
private setRoutes(map: SortedMap<ApplicationBuilderMiddleware | IRouter | SortedMap<ApplicationBuilderMiddleware>>, handler: ApplicationBuilderMiddleware | IRouter, hostingPath: HostingPath, order: number | undefined = undefined) {
348348
if (hostingPath === "*") {
349349
const existingMap = map.get(hostingPath) as SortedMap<ApplicationBuilderMiddleware> || new SortedMap<ApplicationBuilderMiddleware>();
350-
existingMap.set(hostingPath, handler, order);
350+
existingMap.set(`${hostingPath}-${order}`, handler, order);
351351
map.set(hostingPath, existingMap, 0);
352352
}
353353
else {

0 commit comments

Comments
 (0)