@increase21/simplenodejs 1.0.18 → 1.0.20
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 +14 -15
- package/dist/index.d.ts +1 -1
- package/dist/typings/general.d.ts +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -53,7 +53,6 @@ Creates and returns the HTTP app instance.
|
|
|
53
53
|
```ts
|
|
54
54
|
const app = CreateSimpleJsHttpServer({
|
|
55
55
|
controllersDir: process.cwd()+ "/controllers",
|
|
56
|
-
trustProxy: true
|
|
57
56
|
});
|
|
58
57
|
|
|
59
58
|
app.listen(3000, () => {
|
|
@@ -148,9 +147,9 @@ Methods can receive parameters, which are passed through the URL pathname. When
|
|
|
148
147
|
|
|
149
148
|
## 🧾 RequestObject (req)
|
|
150
149
|
|
|
151
|
-
Available on every
|
|
150
|
+
Available on every controller.
|
|
152
151
|
|
|
153
|
-
|
|
|
152
|
+
| Additional Properties | Type | Description |
|
|
154
153
|
|---------|------|-------------|
|
|
155
154
|
| `req.url` | `string` | Request URL |
|
|
156
155
|
| `req.method` | `string` | HTTP method |
|
|
@@ -163,7 +162,7 @@ Available on every route handler.
|
|
|
163
162
|
|
|
164
163
|
## 🧾 ResponseObject (res)
|
|
165
164
|
|
|
166
|
-
|
|
|
165
|
+
| Additional Methods | Params | Description |
|
|
167
166
|
|--------|--------|-------------|
|
|
168
167
|
| `res.status(code)` | `number` | Set HTTP status |
|
|
169
168
|
| `res.json(data)` | `any` | Send JSON response |
|
|
@@ -185,15 +184,15 @@ Registers a middleware that runs before controllers.
|
|
|
185
184
|
### Middleware Signature
|
|
186
185
|
|
|
187
186
|
```ts
|
|
188
|
-
(req: RequestObject, res: ResponseObject, next: () => Promise<void> | void) => Promise<
|
|
187
|
+
(req: RequestObject, res: ResponseObject, next: () => Promise<void> | void) => Promise<any> | void
|
|
189
188
|
```
|
|
190
189
|
|
|
191
190
|
### Example
|
|
192
191
|
|
|
193
192
|
```ts
|
|
194
|
-
app.use(
|
|
193
|
+
app.use((req, res, next) => {
|
|
195
194
|
console.log(req.method, req.url);
|
|
196
|
-
|
|
195
|
+
next();
|
|
197
196
|
});
|
|
198
197
|
```
|
|
199
198
|
|
|
@@ -203,7 +202,7 @@ app.use(async (req, res, next) => {
|
|
|
203
202
|
|
|
204
203
|
Registers a global error handler.
|
|
205
204
|
|
|
206
|
-
###
|
|
205
|
+
### ErrorHandler
|
|
207
206
|
app.useError() registers global error-handling middleware.
|
|
208
207
|
It catches all errors thrown anywhere in the request lifecycle — including:
|
|
209
208
|
• Errors thrown inside middlewares
|
|
@@ -234,12 +233,12 @@ type Plugin = (app: SimpleJsServer, opts?: any) => Promise<any>|void;
|
|
|
234
233
|
|
|
235
234
|
### Built-In Plugins
|
|
236
235
|
|
|
237
|
-
| name | Description |
|
|
238
|
-
|
|
239
|
-
| `SimpleJsSecurityPlugin` | CORS, RateLimit, Helmet |
|
|
240
|
-
| `SimpleJsJWTPlugin` | JWT protection|
|
|
241
|
-
| `SimpleJsIPWhitelistPlugin` | Restricting IP addresses |
|
|
242
|
-
| `SimpleJsCookiePlugin` |
|
|
236
|
+
| name | Description | Status |
|
|
237
|
+
|-----------|-------------|-----------|
|
|
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 |
|
|
243
242
|
|
|
244
243
|
---
|
|
245
244
|
|
|
@@ -301,7 +300,7 @@ app.use(SetBodyParser({ limit: "2mb" }));
|
|
|
301
300
|
- Always enable `SetSecurityHeaders`
|
|
302
301
|
- Enable `SetRateLimiter` on public APIs
|
|
303
302
|
- Validate request body
|
|
304
|
-
- Use `trustProxy: true` only behind trusted proxies
|
|
303
|
+
<!-- - Use `trustProxy: true` only behind trusted proxies -->
|
|
305
304
|
- Avoid leaking stack traces in production
|
|
306
305
|
|
|
307
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
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@increase21/simplenodejs",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Lightweight Node.js HTTP framework with
|
|
3
|
+
"version": "1.0.20",
|
|
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",
|