nestjs-ip-filter 0.1.0 → 0.1.1
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 +8 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@ Now we can filter the incoming requests by setting the whitelist and the blackli
|
|
|
4
4
|
|
|
5
5
|
It will work using the built-in feature in NestJS, **Guard**, so it works like a charm as it should be and as much as it should do.
|
|
6
6
|
|
|
7
|
+
The Guard recognizes the requester's IP address using [@supercharge/request-ip](https://www.npmjs.com/package/request-ip) package.
|
|
8
|
+
|
|
7
9
|
## How to install
|
|
8
10
|
|
|
9
11
|
Simply, install using NPM by the following command.
|
|
@@ -16,7 +18,7 @@ npm install nestjs-ip-filter
|
|
|
16
18
|
|
|
17
19
|
### Use Regex for the IP list
|
|
18
20
|
|
|
19
|
-
You can use Regex format string for the IP ranges.
|
|
21
|
+
You can use the Regex format string for the IP ranges.
|
|
20
22
|
|
|
21
23
|
For a simple example, if you want to allow the private network hosts in `192.168.0.1/16`, you can write the Regex string like the below.
|
|
22
24
|
|
|
@@ -38,13 +40,13 @@ Check the other use cases.
|
|
|
38
40
|
(^11[0-9].*)
|
|
39
41
|
```
|
|
40
42
|
|
|
41
|
-
And, writing in this way also works on this
|
|
43
|
+
And, writing in this way also works on this package.
|
|
42
44
|
|
|
43
45
|
But be aware of that you should write the Regex string very carefully to avoid allowing unwanted incoming IP addresses.
|
|
44
46
|
|
|
45
|
-
###
|
|
47
|
+
### Basic usage for Whitelist
|
|
46
48
|
|
|
47
|
-
You can initialize the dedicated Guard using non-async or async mode, as
|
|
49
|
+
You can initialize the dedicated Guard using non-async or async mode, as the other NestJS packages support.
|
|
48
50
|
|
|
49
51
|
Use `forRoot` for the static IP address list.
|
|
50
52
|
|
|
@@ -81,7 +83,7 @@ After setting up the `IpFilter` module with the `forRoot*` method, this will acc
|
|
|
81
83
|
|
|
82
84
|
You can deny the requests that are from the blacklist IPs.
|
|
83
85
|
|
|
84
|
-
Use `blacklist` option to let the
|
|
86
|
+
Use `blacklist` option to let the Guard know the list.
|
|
85
87
|
|
|
86
88
|
```typescript
|
|
87
89
|
// If it would like to get the whitelist IPs from a config file,
|
|
@@ -128,7 +130,7 @@ When the Guard throws an exception, it will also carry some informative data lik
|
|
|
128
130
|
|
|
129
131
|
### Inject IpFilterService
|
|
130
132
|
|
|
131
|
-
If you want, you can inject `IpFilterService` into your code and can see current options you put when you
|
|
133
|
+
If you want, you can inject `IpFilterService` into your code and can see current options you put when you initialize it. And, you can set the whitelist and the blacklist too.
|
|
132
134
|
|
|
133
135
|
Inject the service using the `IPFILTER_TOKEN` module.
|
|
134
136
|
|