-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d0498a
commit 880cf2b
Showing
7 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.