@lytical/app 1.0.10 → 1.0.11
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 +35 -27
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ a typescript api server library built for your express project, with dependency
|
|
|
13
13
|
install packages:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
npm install @lytical/app
|
|
16
|
+
npm install @lytical/app express
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
after installing, configure your `tsconfig.json` file to enable decorators.
|
|
@@ -72,7 +72,8 @@ for the above project structure:
|
|
|
72
72
|
}
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
a simple project template / example can be found in github
|
|
75
|
+
a simple project template / example can be found in github\
|
|
76
|
+
(https://github.com/lytical/ts-app-example)
|
|
76
77
|
|
|
77
78
|
## usage
|
|
78
79
|
|
|
@@ -145,7 +146,8 @@ import { example_middleware_class } from '../middleware/example-mw';
|
|
|
145
146
|
|
|
146
147
|
/**
|
|
147
148
|
* Example route class
|
|
148
|
-
* Use for router class(es)
|
|
149
|
+
* Use for router class(es) to auto app.use() registration for
|
|
150
|
+
* routes; dependent middleware; and dependency injection
|
|
149
151
|
*/
|
|
150
152
|
@app_route({ route: '/example' })
|
|
151
153
|
export class example_route_class {
|
|
@@ -173,7 +175,7 @@ export class example_route_class {
|
|
|
173
175
|
],
|
|
174
176
|
// you may indicate an error handler middleware at the route level.
|
|
175
177
|
// the default error handler will be used if not indicated here.
|
|
176
|
-
error_handler: example_error_handler
|
|
178
|
+
error_handler: example_error_handler,
|
|
177
179
|
})
|
|
178
180
|
post_handler(rqs: Request, rsp: Response, nxt: NextFunction) {
|
|
179
181
|
rsp.json({ body: rqs.body, locals: rsp.locals }).end();
|
|
@@ -202,41 +204,51 @@ import app, { app_evt } from './lib/app';
|
|
|
202
204
|
// 3. server_listening
|
|
203
205
|
|
|
204
206
|
app.once(app_evt.create_server, (cfg) => {
|
|
205
|
-
// set the event parameter (evt.server) property to
|
|
206
|
-
//
|
|
207
|
+
// set the event parameter (evt.server) property to
|
|
208
|
+
// provide the server instance of your choice.
|
|
209
|
+
|
|
207
210
|
// e.g.
|
|
208
211
|
// evt.server = createHttpsServer(evt.express, my_https_options);
|
|
209
|
-
|
|
210
|
-
// a standard http server instance is created by default,
|
|
211
|
-
//
|
|
212
|
-
|
|
212
|
+
|
|
213
|
+
// a standard http server instance is created by default,
|
|
214
|
+
// if no server is provided.
|
|
215
|
+
|
|
216
|
+
// evt.root_route can be modified to change the root route
|
|
217
|
+
// where auto registered routes are mounted.
|
|
218
|
+
|
|
213
219
|
// default is '/api'.
|
|
214
|
-
|
|
215
|
-
// push async operations (Promise) that fetch encryption keys, ...
|
|
216
|
-
//
|
|
217
|
-
|
|
218
|
-
//
|
|
219
|
-
//
|
|
220
|
+
|
|
221
|
+
// push async operations (Promise) that fetch encryption keys, ...
|
|
222
|
+
// into the event parameter (evt.wait_for.push(...)).
|
|
223
|
+
|
|
224
|
+
// add middleware into the pipeline (evt.express.use(...)),
|
|
225
|
+
// before auto registered routes are added.
|
|
226
|
+
|
|
227
|
+
// this is also the last chance to register dependencies
|
|
228
|
+
// in the ioc collection, before the container is created.
|
|
220
229
|
console.log(`the root route is (${cfg.root_route})`);
|
|
221
230
|
});
|
|
222
231
|
|
|
223
232
|
app.once(app_evt.server_starting, (cfg) => {
|
|
224
233
|
// use to modify the server listening configuration before it is started.
|
|
225
|
-
|
|
234
|
+
|
|
226
235
|
// all auto registered routes have been added at this point.
|
|
227
|
-
|
|
228
|
-
// you may add middleware to the app pipeline (evt.express.use(...)),
|
|
236
|
+
|
|
237
|
+
// you may add middleware to the app pipeline (evt.express.use(...)),
|
|
238
|
+
// after the auto registered routes.
|
|
239
|
+
|
|
229
240
|
// for example, to add error handling middleware, ...
|
|
230
|
-
|
|
231
|
-
// push async operations (Promise) that may fetch data or
|
|
232
|
-
//
|
|
241
|
+
|
|
242
|
+
// push async operations (Promise) that may fetch data or
|
|
243
|
+
// does some kind of i/o, ... into (evt.wait_for.push(...)).
|
|
244
|
+
|
|
233
245
|
// the ioc container is also ready at this point.
|
|
234
246
|
console.log(`the hostname is (${cfg.hostname})`);
|
|
235
247
|
});
|
|
236
248
|
|
|
237
249
|
app.once(app_evt.server_listening, () => {
|
|
238
250
|
// emitted when the server is listening
|
|
239
|
-
|
|
251
|
+
|
|
240
252
|
// use it to perform operations after the server starts listening.
|
|
241
253
|
// this is the last event from the app, when it's considered started.
|
|
242
254
|
});
|
|
@@ -244,10 +256,6 @@ app.once(app_evt.server_listening, () => {
|
|
|
244
256
|
app.start();
|
|
245
257
|
```
|
|
246
258
|
|
|
247
|
-
## documentation
|
|
248
|
-
|
|
249
|
-
todo: working on this right now...
|
|
250
|
-
|
|
251
259
|
stay tuned! i have more packages to come.`
|
|
252
260
|
|
|
253
261
|
_lytical(r) is a registered trademark of lytical, inc. all rights are reserved._
|
package/package.json
CHANGED