@lytical/app 1.0.11 → 1.0.13
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 +24 -14
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -20,10 +20,10 @@ after installing, configure your `tsconfig.json` file to enable decorators.
|
|
|
20
20
|
|
|
21
21
|
```json
|
|
22
22
|
// tsconfig.json
|
|
23
|
+
|
|
23
24
|
{
|
|
24
25
|
"compilerOptions": {
|
|
25
|
-
"experimentalDecorators": true
|
|
26
|
-
"emitDecoratorMetadata": true
|
|
26
|
+
"experimentalDecorators": true
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
```
|
|
@@ -31,16 +31,15 @@ after installing, configure your `tsconfig.json` file to enable decorators.
|
|
|
31
31
|
if this is a new project, we recommended the following project structure:
|
|
32
32
|
|
|
33
33
|
```
|
|
34
|
-
project
|
|
35
|
-
|-
|
|
36
|
-
|-
|
|
37
|
-
| |- middleware
|
|
34
|
+
project\
|
|
35
|
+
|- src\
|
|
36
|
+
| |- middleware\
|
|
38
37
|
| | |- my-middleware.ts
|
|
39
38
|
| | |- ...
|
|
40
|
-
| |- routes
|
|
39
|
+
| |- routes\
|
|
41
40
|
| | |- my-route.ts
|
|
42
41
|
| | |- ...
|
|
43
|
-
| |- services
|
|
42
|
+
| |- services\
|
|
44
43
|
| | |- my-service.ts
|
|
45
44
|
| | |- ...
|
|
46
45
|
| |- index.ts
|
|
@@ -55,6 +54,7 @@ for the above project structure:
|
|
|
55
54
|
|
|
56
55
|
```json
|
|
57
56
|
// tsconfig.json
|
|
57
|
+
|
|
58
58
|
{
|
|
59
59
|
"compilerOptions": {
|
|
60
60
|
"rootDir": "src",
|
|
@@ -67,12 +67,17 @@ for the above project structure:
|
|
|
67
67
|
|
|
68
68
|
```json
|
|
69
69
|
// package.json
|
|
70
|
+
|
|
70
71
|
{
|
|
71
72
|
"main": "./{index.js,routes/**/*.js}"
|
|
72
73
|
}
|
|
73
74
|
```
|
|
74
75
|
|
|
75
|
-
|
|
76
|
+
**note:** your route handlers can be place anywhere... just make sure you import them before starting the app.\
|
|
77
|
+
(e.g. `import './contact/routes/index'`)
|
|
78
|
+
|
|
79
|
+
## example app
|
|
80
|
+
a simple project template / example can be found at github\
|
|
76
81
|
(https://github.com/lytical/ts-app-example)
|
|
77
82
|
|
|
78
83
|
## usage
|
|
@@ -80,10 +85,11 @@ a simple project template / example can be found in github\
|
|
|
80
85
|
create your injectable service class(es) to implement the business logic.
|
|
81
86
|
|
|
82
87
|
```typescript
|
|
88
|
+
// src/services/example-svc.ts
|
|
89
|
+
|
|
83
90
|
import { ioc_injectable } from '@lytical/ioc';
|
|
84
91
|
|
|
85
92
|
@ioc_injectable()
|
|
86
|
-
// src/services/example-svc.ts
|
|
87
93
|
export class example_svc {
|
|
88
94
|
async get_message() {
|
|
89
95
|
return 'Hello from example_svc!';
|
|
@@ -99,6 +105,7 @@ create your middleware classes
|
|
|
99
105
|
|
|
100
106
|
```typescript
|
|
101
107
|
// src/middleware/example-mw.ts
|
|
108
|
+
|
|
102
109
|
import type { Request, Response, NextFunction } from 'express';
|
|
103
110
|
|
|
104
111
|
import { ioc_inject } from '@lytical/ioc';
|
|
@@ -128,6 +135,7 @@ create your route handler(s)
|
|
|
128
135
|
|
|
129
136
|
```typescript
|
|
130
137
|
// src/routes/example.ts
|
|
138
|
+
|
|
131
139
|
import express, {
|
|
132
140
|
type Request,
|
|
133
141
|
type Response,
|
|
@@ -187,6 +195,7 @@ now just import app and invoke `start()`
|
|
|
187
195
|
|
|
188
196
|
```typescript
|
|
189
197
|
// src/index.ts
|
|
198
|
+
|
|
190
199
|
import app from '@lytical/app';
|
|
191
200
|
|
|
192
201
|
app.start();
|
|
@@ -196,6 +205,7 @@ app.start();
|
|
|
196
205
|
|
|
197
206
|
```typescript
|
|
198
207
|
// src/index.ts
|
|
208
|
+
|
|
199
209
|
import app, { app_evt } from './lib/app';
|
|
200
210
|
|
|
201
211
|
// app events occur in the following order:
|
|
@@ -203,7 +213,7 @@ import app, { app_evt } from './lib/app';
|
|
|
203
213
|
// 2. server_starting
|
|
204
214
|
// 3. server_listening
|
|
205
215
|
|
|
206
|
-
app.once(app_evt.create_server, (
|
|
216
|
+
app.once(app_evt.create_server, (evt) => {
|
|
207
217
|
// set the event parameter (evt.server) property to
|
|
208
218
|
// provide the server instance of your choice.
|
|
209
219
|
|
|
@@ -226,10 +236,10 @@ app.once(app_evt.create_server, (cfg) => {
|
|
|
226
236
|
|
|
227
237
|
// this is also the last chance to register dependencies
|
|
228
238
|
// in the ioc collection, before the container is created.
|
|
229
|
-
console.log(`the root route is (${
|
|
239
|
+
console.log(`the root route is (${evt.root_route})`);
|
|
230
240
|
});
|
|
231
241
|
|
|
232
|
-
app.once(app_evt.server_starting, (
|
|
242
|
+
app.once(app_evt.server_starting, (evt) => {
|
|
233
243
|
// use to modify the server listening configuration before it is started.
|
|
234
244
|
|
|
235
245
|
// all auto registered routes have been added at this point.
|
|
@@ -243,7 +253,7 @@ app.once(app_evt.server_starting, (cfg) => {
|
|
|
243
253
|
// does some kind of i/o, ... into (evt.wait_for.push(...)).
|
|
244
254
|
|
|
245
255
|
// the ioc container is also ready at this point.
|
|
246
|
-
console.log(`the hostname is (${
|
|
256
|
+
console.log(`the hostname is (${evt.hostname})`);
|
|
247
257
|
});
|
|
248
258
|
|
|
249
259
|
app.once(app_evt.server_listening, () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lytical/app",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "a typescript api server library built for your express project, with dependency injection support and auto router registration",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"private": false,
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"license": "ISC",
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@lytical/ioc": "^1.0.
|
|
36
|
+
"@lytical/ioc": "^1.0.6",
|
|
37
37
|
"express": "^5.2.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|