@increase21/simplenodejs 1.0.17 → 1.0.18
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 +33 -19
- package/dist/utils/simpleController.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,17 +33,7 @@ npm install @increase21/simplenodejs
|
|
|
33
33
|
|
|
34
34
|
```ts
|
|
35
35
|
import { CreateSimpleJsHttpServer } from "@increase21/simplenodejs";
|
|
36
|
-
|
|
37
|
-
const app = CreateSimpleJsHttpServer({
|
|
38
|
-
controllersDir: process.cwd()+ "/controllers",
|
|
39
|
-
trustProxy: true
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
app.listen(3000, () => {
|
|
43
|
-
console.log("Server running on http://localhost:3000");
|
|
44
|
-
});
|
|
45
36
|
```
|
|
46
|
-
|
|
47
37
|
---
|
|
48
38
|
|
|
49
39
|
## ⚙️ CreateSimpleJsHttpServer(options)
|
|
@@ -63,10 +53,12 @@ Creates and returns the HTTP app instance.
|
|
|
63
53
|
```ts
|
|
64
54
|
const app = CreateSimpleJsHttpServer({
|
|
65
55
|
controllersDir: process.cwd()+ "/controllers",
|
|
56
|
+
trustProxy: true
|
|
66
57
|
});
|
|
67
58
|
|
|
68
|
-
app.listen(
|
|
69
|
-
|
|
59
|
+
app.listen(3000, () => {
|
|
60
|
+
console.log("Server running on http://localhost:3000");
|
|
61
|
+
});
|
|
70
62
|
```
|
|
71
63
|
|
|
72
64
|
---
|
|
@@ -74,7 +66,7 @@ app.listen(4000,callback)
|
|
|
74
66
|
## 📁 Controllers
|
|
75
67
|
|
|
76
68
|
Controllers are auto-loaded from `controllersDir`.
|
|
77
|
-
#### Running
|
|
69
|
+
#### Running an endpoint using RunRequest
|
|
78
70
|
##### ./controllers/{servicefolder}/auth.ts
|
|
79
71
|
#### or
|
|
80
72
|
#### ./controllers/{servicefolder}/auth.js
|
|
@@ -93,9 +85,11 @@ export default AuthControllers extends SimpleNodeJsController {
|
|
|
93
85
|
}
|
|
94
86
|
};
|
|
95
87
|
```
|
|
96
|
-
Available on POST|GET|PUT|DELETE at http://baseURl/{servicefolder}/auth/account
|
|
97
88
|
|
|
98
|
-
|
|
89
|
+
The above endpoint is accessible on http://baseURl/{servicefolder}/auth/account.
|
|
90
|
+
The endpoint receives optional parameter (id:string) which can be passed in the url e.g http://baseURl/{servicefolder}/auth/account/{id}
|
|
91
|
+
|
|
92
|
+
#### Running an endpoint without RunRequest
|
|
99
93
|
```ts
|
|
100
94
|
export default AuthControllers extends SimpleNodeJsController {
|
|
101
95
|
|
|
@@ -106,6 +100,26 @@ export default AuthControllers extends SimpleNodeJsController {
|
|
|
106
100
|
}
|
|
107
101
|
};
|
|
108
102
|
```
|
|
103
|
+
### Endpoint Naming
|
|
104
|
+
Endpoints are defined using camelCase method names in controller files and are exposed as kebab-case in the URL path.
|
|
105
|
+
```ts
|
|
106
|
+
async vehicleList(id:string) {}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
```code
|
|
110
|
+
/vehicle-list
|
|
111
|
+
/vehicle-list/{id}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
async vehicle() {}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```code
|
|
119
|
+
/vehicle
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
109
123
|
|
|
110
124
|
### Controller Object Params
|
|
111
125
|
Each method defined in a controller file is exposed as an endpoint by SimpleNodeJsController.
|
|
@@ -130,7 +144,7 @@ Methods can receive parameters, which are passed through the URL pathname. When
|
|
|
130
144
|
patch?: 'required' | 'optional',
|
|
131
145
|
}
|
|
132
146
|
}
|
|
133
|
-
|
|
147
|
+
```
|
|
134
148
|
|
|
135
149
|
## 🧾 RequestObject (req)
|
|
136
150
|
|
|
@@ -215,7 +229,7 @@ Registers a plugin.
|
|
|
215
229
|
### Plugin Shape
|
|
216
230
|
|
|
217
231
|
```ts
|
|
218
|
-
type Plugin = (app: SimpleJsServer, opts?: any) =>
|
|
232
|
+
type Plugin = (app: SimpleJsServer, opts?: any) => Promise<any>|void;
|
|
219
233
|
```
|
|
220
234
|
|
|
221
235
|
### Built-In Plugins
|
|
@@ -240,10 +254,10 @@ All the standard http headers
|
|
|
240
254
|
|
|
241
255
|
### Usage
|
|
242
256
|
```ts
|
|
243
|
-
app.use(
|
|
257
|
+
app.use(SetRequestCORS({
|
|
244
258
|
"Access-Control-Allow-Origin": "*",
|
|
245
259
|
"X-Frame-Options": "DENY",
|
|
246
|
-
}
|
|
260
|
+
}));
|
|
247
261
|
```
|
|
248
262
|
|
|
249
263
|
---
|
|
@@ -14,6 +14,6 @@ export declare class SimpleNodeJsController {
|
|
|
14
14
|
}): void;
|
|
15
15
|
/** framework-internal method */
|
|
16
16
|
__checkContext(): void;
|
|
17
|
-
protected RunRequest(handlers: SubRequestHandler, params?: SimpleJsPrivateMethodProps): any;
|
|
17
|
+
protected RunRequest(handlers: SubRequestHandler, params?: Partial<SimpleJsPrivateMethodProps>): any;
|
|
18
18
|
}
|
|
19
19
|
export {};
|
package/package.json
CHANGED