@tahminator/sapling 1.5.26 → 1.5.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,14 +56,20 @@ pnpm install @tahminator/sapling
|
|
|
56
56
|
|
|
57
57
|
```typescript
|
|
58
58
|
import express from "express";
|
|
59
|
-
import {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
import { Sapling, Controller, GET, POST, ResponseEntity, Class, HttpStatus, MiddlewareClass, Middleware } from "@tahminator/sapling";
|
|
60
|
+
|
|
61
|
+
@MiddlewareClass()
|
|
62
|
+
class LoggingMiddleware {
|
|
63
|
+
@Middleware()
|
|
64
|
+
loggingMiddleware(
|
|
65
|
+
request: express.Request,
|
|
66
|
+
response: express.Response,
|
|
67
|
+
next: express.NextFunction,
|
|
68
|
+
): void {
|
|
69
|
+
console.log(request.path);
|
|
70
|
+
next();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
67
73
|
|
|
68
74
|
@Controller({ prefix: "/api" })
|
|
69
75
|
class HelloController {
|
|
@@ -90,7 +96,12 @@ class UserController {
|
|
|
90
96
|
const app = express();
|
|
91
97
|
Sapling.registerApp(app);
|
|
92
98
|
|
|
93
|
-
// @Controller and
|
|
99
|
+
// @MiddlewareClass should be registered first before @Controller and should be registered in order
|
|
100
|
+
// @Injectable classes will automatically be formed into singletons by Sapling behind the scenes!
|
|
101
|
+
const middlewares: Class<any>[] = [LoggingMiddleware];
|
|
102
|
+
middlewares.map(Sapling.resolve).forEach((r) => app.use(r));
|
|
103
|
+
|
|
104
|
+
// @Controller can be registered in any order.
|
|
94
105
|
// @Injectable classes will automatically be formed into singletons by Sapling behind the scenes!
|
|
95
106
|
const controllers: Class<any>[] = [HelloController, UserController];
|
|
96
107
|
controllers.map(Sapling.resolve).forEach((r) => app.use(r));
|