@increase21/simplenodejs 1.0.17 → 1.0.19

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 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)
@@ -65,8 +55,9 @@ const app = CreateSimpleJsHttpServer({
65
55
  controllersDir: process.cwd()+ "/controllers",
66
56
  });
67
57
 
68
- app.listen(4000,callback)
69
-
58
+ app.listen(3000, () => {
59
+ console.log("Server running on http://localhost:3000");
60
+ });
70
61
  ```
71
62
 
72
63
  ---
@@ -74,7 +65,7 @@ app.listen(4000,callback)
74
65
  ## 📁 Controllers
75
66
 
76
67
  Controllers are auto-loaded from `controllersDir`.
77
- #### Running Multiple Methods
68
+ #### Running an endpoint using RunRequest
78
69
  ##### ./controllers/{servicefolder}/auth.ts
79
70
  #### or
80
71
  #### ./controllers/{servicefolder}/auth.js
@@ -93,9 +84,11 @@ export default AuthControllers extends SimpleNodeJsController {
93
84
  }
94
85
  };
95
86
  ```
96
- Available on POST|GET|PUT|DELETE at http://baseURl/{servicefolder}/auth/account
97
87
 
98
- #### Running Single Method
88
+ The above endpoint is accessible on http://baseURl/{servicefolder}/auth/account.
89
+ The endpoint receives optional parameter (id:string) which can be passed in the url e.g http://baseURl/{servicefolder}/auth/account/{id}
90
+
91
+ #### Running an endpoint without RunRequest
99
92
  ```ts
100
93
  export default AuthControllers extends SimpleNodeJsController {
101
94
 
@@ -106,6 +99,26 @@ export default AuthControllers extends SimpleNodeJsController {
106
99
  }
107
100
  };
108
101
  ```
102
+ ### Endpoint Naming
103
+ Endpoints are defined using camelCase method names in controller files and are exposed as kebab-case in the URL path.
104
+ ```ts
105
+ async vehicleList(id:string) {}
106
+ ```
107
+
108
+ ```code
109
+ /vehicle-list
110
+ /vehicle-list/{id}
111
+ ```
112
+
113
+ ```ts
114
+ async vehicle() {}
115
+ ```
116
+
117
+ ```code
118
+ /vehicle
119
+ ```
120
+
121
+ ---
109
122
 
110
123
  ### Controller Object Params
111
124
  Each method defined in a controller file is exposed as an endpoint by SimpleNodeJsController.
@@ -130,13 +143,13 @@ Methods can receive parameters, which are passed through the URL pathname. When
130
143
  patch?: 'required' | 'optional',
131
144
  }
132
145
  }
133
- ```
146
+ ```
134
147
 
135
148
  ## 🧾 RequestObject (req)
136
149
 
137
- Available on every route handler.
150
+ Available on every controller.
138
151
 
139
- | Property | Type | Description |
152
+ | Additional Properties | Type | Description |
140
153
  |---------|------|-------------|
141
154
  | `req.url` | `string` | Request URL |
142
155
  | `req.method` | `string` | HTTP method |
@@ -149,7 +162,7 @@ Available on every route handler.
149
162
 
150
163
  ## 🧾 ResponseObject (res)
151
164
 
152
- | Method | Params | Description |
165
+ | Additional Methods | Params | Description |
153
166
  |--------|--------|-------------|
154
167
  | `res.status(code)` | `number` | Set HTTP status |
155
168
  | `res.json(data)` | `any` | Send JSON response |
@@ -171,15 +184,15 @@ Registers a middleware that runs before controllers.
171
184
  ### Middleware Signature
172
185
 
173
186
  ```ts
174
- (req: RequestObject, res: ResponseObject, next: () => Promise<void> | void) => Promise<void> | void
187
+ (req: RequestObject, res: ResponseObject, next: () => Promise<void> | void) => Promise<any> | void
175
188
  ```
176
189
 
177
190
  ### Example
178
191
 
179
192
  ```ts
180
- app.use(async (req, res, next) => {
193
+ app.use((req, res, next) => {
181
194
  console.log(req.method, req.url);
182
- await next();
195
+ next();
183
196
  });
184
197
  ```
185
198
 
@@ -189,7 +202,7 @@ app.use(async (req, res, next) => {
189
202
 
190
203
  Registers a global error handler.
191
204
 
192
- ### Signature
205
+ ### ErrorHandler
193
206
  app.useError() registers global error-handling middleware.
194
207
  It catches all errors thrown anywhere in the request lifecycle — including:
195
208
  • Errors thrown inside middlewares
@@ -215,17 +228,17 @@ Registers a plugin.
215
228
  ### Plugin Shape
216
229
 
217
230
  ```ts
218
- type Plugin = (app: SimpleJsServer, opts?: any) => void | Promise<void>;
231
+ type Plugin = (app: SimpleJsServer, opts?: any) => Promise<any>|void;
219
232
  ```
220
233
 
221
234
  ### Built-In Plugins
222
235
 
223
- | name | Description |
236
+ | name | Description | Status |
224
237
  |-----------|-------------|
225
- | `SimpleJsSecurityPlugin` | CORS, RateLimit, Helmet |
226
- | `SimpleJsJWTPlugin` | JWT protection|
227
- | `SimpleJsIPWhitelistPlugin` | Restricting IP addresses |
228
- | `SimpleJsCookiePlugin` | Restricting IP addresses |
238
+ | `SimpleJsSecurityPlugin` | CORS, RateLimit, Helmet | Available |
239
+ | `SimpleJsJWTPlugin` | JWT protection| Coming soon |
240
+ | `SimpleJsIPWhitelistPlugin` | Restricting IP addresses | Coming soon |
241
+ | `SimpleJsCookiePlugin` | Cookies Plugin | Coming soon |
229
242
 
230
243
  ---
231
244
 
@@ -240,10 +253,10 @@ All the standard http headers
240
253
 
241
254
  ### Usage
242
255
  ```ts
243
- app.use(app=>SetRequestCORS(app, [{
256
+ app.use(SetRequestCORS({
244
257
  "Access-Control-Allow-Origin": "*",
245
258
  "X-Frame-Options": "DENY",
246
- }]));
259
+ }));
247
260
  ```
248
261
 
249
262
  ---
@@ -287,7 +300,7 @@ app.use(SetBodyParser({ limit: "2mb" }));
287
300
  - Always enable `SetSecurityHeaders`
288
301
  - Enable `SetRateLimiter` on public APIs
289
302
  - Validate request body
290
- - Use `trustProxy: true` only behind trusted proxies
303
+ <!-- - Use `trustProxy: true` only behind trusted proxies -->
291
304
  - Avoid leaking stack traces in production
292
305
 
293
306
  ---
package/dist/index.d.ts CHANGED
@@ -2,4 +2,4 @@ export { SimpleNodeJsController } from "./utils/simpleController";
2
2
  export { CreateSimpleJsHttpServer } from "./server";
3
3
  export { SetRequestCORS, SetRateLimiter, SetBodyParser } from "./utils/simpleMiddleware";
4
4
  export * from "./utils/simplePlugins";
5
- export type { SimpleJsPrivateMethodProps } from "./typings/general";
5
+ export type { SimpleJsPrivateMethodProps, Middleware as SimpleJsMiddleware } from "./typings/general";
@@ -5,7 +5,7 @@ export type HttpMethod = "get" | "post" | "put" | "patch" | "delete";
5
5
  export type ObjectPayload = {
6
6
  [key: string]: any;
7
7
  };
8
- export type Middleware = (req: RequestObject, res: ResponseObject, next: () => Promise<any> | void, errorHandler?: () => void) => Promise<any> | void;
8
+ export type Middleware = (req: RequestObject, res: ResponseObject, next: () => Promise<any> | void) => Promise<any> | void;
9
9
  export type ErrorMiddleware = (err: any, req: RequestObject, res: ResponseObject, next: Next) => Promise<boolean> | void;
10
10
  export interface SimpleJsServer extends http.Server {
11
11
  use(mw: Middleware): Promise<any> | void;
@@ -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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@increase21/simplenodejs",
3
- "version": "1.0.17",
4
- "description": "Lightweight Node.js HTTP framework with middleware and plugins",
3
+ "version": "1.0.19",
4
+ "description": "Lightweight Node.js HTTP framework with middlewares and plugins",
5
5
  "dev": "dist/index.js",
6
6
  "bugs": "https://github.com/increase21/simplenodejs/issues",
7
7
  "main": "dist/index.js",