vpndetection-fastify 2.0.8 → 2.0.10
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 +18 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ import { vpndetection } from 'vpndetection-fastify';
|
|
|
23
23
|
|
|
24
24
|
// trustProxy names the proxy whose X-Forwarded-For Fastify believes; see
|
|
25
25
|
// "Where the client address comes from" below.
|
|
26
|
-
const app = Fastify({ trustProxy: '
|
|
26
|
+
const app = Fastify({ trustProxy: 'loopback' });
|
|
27
27
|
|
|
28
28
|
await app.register(vpndetection, { apiKey: process.env.VPNDETECTION_API_KEY });
|
|
29
29
|
|
|
@@ -80,7 +80,7 @@ By default the plugin uses `request.ip`, which is Fastify's own accessor. **Fast
|
|
|
80
80
|
If you are behind a proxy you control, setting Fastify's own option to that proxy's address is the right fix and everything else here follows from it:
|
|
81
81
|
|
|
82
82
|
```js
|
|
83
|
-
const app = Fastify({ trustProxy: '
|
|
83
|
+
const app = Fastify({ trustProxy: 'loopback' }); // a proxy on the same machine, over 127.0.0.1 or ::1
|
|
84
84
|
const app = Fastify({ trustProxy: '10.0.0.0/8' }); // or your load balancer's subnet
|
|
85
85
|
```
|
|
86
86
|
|
|
@@ -148,6 +148,22 @@ await app.register(vpndetection, {
|
|
|
148
148
|
|
|
149
149
|
If you already hold a `VPNDetection` client, pass it as `client` and the plugin will share it rather than building a second cache.
|
|
150
150
|
|
|
151
|
+
A registration nested in a scope that already has one runs after it, and its answer replaces the outer one on the routes it covers. Give both the same client and the second lookup is a cache hit, so this flags every account route and blocks only at checkout, for one request per visitor:
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
const client = new VPNDetection({ apiKey: KEY }); // from 'vpndetection'
|
|
155
|
+
|
|
156
|
+
await app.register(async (account) => {
|
|
157
|
+
await account.register(vpndetection, { client });
|
|
158
|
+
account.post('/signup', signupHandler);
|
|
159
|
+
|
|
160
|
+
await account.register(async (checkout) => {
|
|
161
|
+
await checkout.register(vpndetection, { client, blockCondition: { isVpn: true } });
|
|
162
|
+
checkout.post('/checkout', checkoutHandler);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
```
|
|
166
|
+
|
|
151
167
|
Beyond a few million distinct visitors a day, stop calling the API per request: [download the dataset](https://vpndetection.io/#databases) and look addresses up locally instead.
|
|
152
168
|
|
|
153
169
|
## Absent is not false
|
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,8 @@ export interface Options extends MiddlewareOptions<FastifyRequest> {
|
|
|
31
31
|
* Registered through `fastify-plugin`, so the decorator and the hook apply to
|
|
32
32
|
* the instance you register it on rather than to a child Fastify would
|
|
33
33
|
* otherwise create. Register it inside a scope to confine it to those routes.
|
|
34
|
+
* A registration nested in a scope that has one runs after it, and its answer
|
|
35
|
+
* replaces the outer one on the routes it covers.
|
|
34
36
|
*/
|
|
35
37
|
export declare const vpndetection: FastifyPluginAsync<Options>;
|
|
36
38
|
/**
|
package/dist/index.js
CHANGED
|
@@ -14,14 +14,19 @@ import fp from 'fastify-plugin';
|
|
|
14
14
|
* Registered through `fastify-plugin`, so the decorator and the hook apply to
|
|
15
15
|
* the instance you register it on rather than to a child Fastify would
|
|
16
16
|
* otherwise create. Register it inside a scope to confine it to those routes.
|
|
17
|
+
* A registration nested in a scope that has one runs after it, and its answer
|
|
18
|
+
* replaces the outer one on the routes it covers.
|
|
17
19
|
*/
|
|
18
20
|
export const vpndetection = fp(async (fastify, options) => {
|
|
19
21
|
const core = createCore(options, defaultIpSelector);
|
|
20
22
|
const onBlocked = options.onBlocked ?? refuse;
|
|
21
23
|
// Decorated up front so the property exists on every request object
|
|
22
24
|
// rather than being added per request, which deoptimizes the shape
|
|
23
|
-
// Fastify builds for them.
|
|
24
|
-
|
|
25
|
+
// Fastify builds for them. Once only: a scope inherits its parent's
|
|
26
|
+
// decorator, and decorating it again throws.
|
|
27
|
+
if (!fastify.hasRequestDecorator('vpndetection')) {
|
|
28
|
+
fastify.decorateRequest('vpndetection', undefined);
|
|
29
|
+
}
|
|
25
30
|
fastify.addHook('onRequest', async (request, reply) => {
|
|
26
31
|
const lookup = await core.evaluate(request);
|
|
27
32
|
if (lookup === undefined) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAIpE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAsBhC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAIpE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAsBhC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAgC,EAAE,CACvD,KAAK,EAAE,OAAwB,EAAE,OAAgB,EAAE,EAAE;IACjD,MAAM,IAAI,GAAG,UAAU,CAAiB,OAAO,EAAE,iBAAiB,CAAC,CAAC;IACpE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,MAAM,CAAC;IAE9C,oEAAoE;IACpE,mEAAmE;IACnE,oEAAoE;IACpE,6CAA6C;IAC7C,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,cAAc,CAAC,EAAE,CAAC;QAC/C,OAAO,CAAC,eAAe,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IACvD,CAAC;IAED,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,EAAE,OAAuB,EAAE,KAAmB,EAAE,EAAE;QAChF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC5C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AAI,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,eAAe,YAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vpndetection-fastify",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.10",
|
|
4
4
|
"description": "Official Fastify plugin for the VPNDetection API. Detect VPNs, proxies, Tor, hosting and CDN visitors on every request.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"fastify-plugin": "^5.0.1",
|
|
48
|
-
"vpndetection": "^5.
|
|
48
|
+
"vpndetection": "^5.4.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"fastify": "4.x || 5.x"
|