Skip to content

Commit

Permalink
Add Middlewares Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikmehta8 committed Oct 30, 2024
1 parent 3d0498a commit 880cf2b
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/middlewares/_category_.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"position": 3,
"link": {
"type": "generated-index",
"description": "Orion Middleware Guide"
"description": "Orion uses various middlewares to handle common tasks like body parsing, CORS, logging, rate-limiting, and security. Each middleware is implemented as a class extending a standard interface to maintain consistency."
}
}
27 changes: 27 additions & 0 deletions docs/middlewares/body-parser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
sidebar_position: 1
---

# Body Parser

## Purpose
This middleware is used to handle parsing of incoming JSON and URL-encoded bodies in `Express.js`. It simplifies request body parsing for APIs.

## Key Features
- Parses JSON bodies automatically using the `body-parser` package.
- Parses URL-encoded form data automatically.

:::tip From the creator
Remember, if you decide you no longer need a middleware, simply delete the file. **Out of necessity, out of existence!**
:::

## Customization
You can configure the `extended` option for URL-encoded data:
- `extended: true` allows for rich objects and arrays to be encoded.
- `extended: false` allows for simple key-value pairs.

```bash
Location: src/middlewares/bodyParserMiddleware.js
```

Visit the **[official documentation](https://www.npmjs.com/package/body-parser)** for more information.
23 changes: 23 additions & 0 deletions docs/middlewares/cors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
sidebar_position: 2
---

# CORS

## Purpose
Enables *Cross-Origin Resource Sharing (CORS)* to allow or restrict resources on a web server depending on the originating domain.

## Key Features
- Uses the popular `cors` package to enable CORS in the Express app.
- Ensures easy handling of cross-domain requests for APIs.

## Customization
You can pass options to the cors function such as:
- `origin`: Configures which domains can access your API.
- `methods`: Defines allowed HTTP methods.

```bash
Location: src/middlewares/corsMiddleware.js
```

Visit the **[official documentation](https://www.npmjs.com/package/cors)** for more information.
21 changes: 21 additions & 0 deletions docs/middlewares/logger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
sidebar_position: 3
---

# Logger - Morgan

## Purpose
Logs incoming HTTP requests using the `morgan` library in a specified format.

## Key Feature
- Uses the `tiny` logging format by default, which includes basic information such as HTTP method, URL, status, and response time.

## Customization
You can switch to other predefined formats or define your own format:
- Predefined formats: `'tiny'`, `'combined'`, `'common'`, `'dev'`, etc.

```bash
Location: src/middlewares/loggerMiddleware.js
```

Visit the **[official documentation](https://www.npmjs.com/package/morgan)** for more information.
23 changes: 23 additions & 0 deletions docs/middlewares/rate-limit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
sidebar_position: 4
---

# Rate Limiting

## Purpose
Limits the number of requests an IP can make to prevent abuse, brute-force attacks, or DoS attacks.

## Key Features
- Uses the `express-rate-limit` library to control the rate of incoming requests.
- Default rate limit is `100` requests per 15 minutes.

## Customization
Modify the `windowMs` and `max` options to adjust the rate limit:
- `windowMs`: The time window in milliseconds.
- `max`: The maximum number of requests an IP can make within the window.

```bash
Location: src/middlewares/rateLimitMiddleware.js
```

Visit the **[official documentation](https://www.npmjs.com/package/express-rate-limit)** for more information.
20 changes: 20 additions & 0 deletions docs/middlewares/security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
sidebar_position: 4
---

# Security

## Purpose
Improves the security of your `Express.js` application by setting various HTTP headers using the `helmet` library.

## Key Feature
- Adds security-related HTTP headers such as `Strict-Transport-Security`, `X-Frame-Options`, and `Content-Security-Policy`.

## Customization
You can configure the Helmet options to enable or disable specific protections.

```bash
Location: src/middlewares/securityMiddleware.js
```

Visit the **[official documentation](https://www.npmjs.com/package/helmet)** for more information.
File renamed without changes.

0 comments on commit 880cf2b

Please sign in to comment.