@anonymilyhq/cli 1.0.1 ā 1.0.3
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 +9 -2
- package/bin/cli.js +3 -2
- package/lib/forwarder.js +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,16 +28,23 @@ anonymily listen <port>
|
|
|
28
28
|
|
|
29
29
|
### Example
|
|
30
30
|
|
|
31
|
-
To forward webhooks to your local development server running on port `3000
|
|
31
|
+
To forward webhooks to your local development server running on port `3000` with a randomly generated endpoint ID:
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
34
|
anonymily listen 3000
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
To specify a custom endpoint ID (e.g., `stripe-test`) so that your URL is consistently `api.anonymily.com/h/stripe-test`:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
anonymily listen 3000 --id stripe-test
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
1. The CLI will output a webhook connection URL and automatically connect via Server-Sent Events.
|
|
38
44
|
2. Send your webhooks to the provided URL.
|
|
39
45
|
3. The CLI will receive the requests natively and forward them precisely to `http://localhost:3000`, preserving exactly the same method, body, queries, and headers.
|
|
40
46
|
|
|
47
|
+
|
|
41
48
|
## Issues
|
|
42
49
|
|
|
43
50
|
If you encounter a bug, please create an issue in the main repository or contact our support.
|
package/bin/cli.js
CHANGED
|
@@ -16,8 +16,9 @@ program
|
|
|
16
16
|
.command('listen')
|
|
17
17
|
.description('Listen for incoming webhooks and forward them to a local port')
|
|
18
18
|
.argument('<port>', 'Local port to forward to (e.g., 8080)')
|
|
19
|
-
.
|
|
20
|
-
|
|
19
|
+
.option('-i, --id <id>', 'Provide a custom endpoint ID to listen to')
|
|
20
|
+
.action((port, options) => {
|
|
21
|
+
const hookId = options.id || generateHookId();
|
|
21
22
|
startForwarding(API_URL, hookId, parseInt(port, 10));
|
|
22
23
|
});
|
|
23
24
|
|
package/lib/forwarder.js
CHANGED
|
@@ -4,7 +4,7 @@ import { logger } from './logger.js';
|
|
|
4
4
|
|
|
5
5
|
export function startForwarding(apiUrl, hookId, port) {
|
|
6
6
|
const webhookUrl = `${apiUrl}/h/${hookId}`;
|
|
7
|
-
const localUrl = `http://
|
|
7
|
+
const localUrl = `http://127.0.0.1:${port}`;
|
|
8
8
|
|
|
9
9
|
logger.success(pc.bold(`\nš Anonymily CLI is running!`));
|
|
10
10
|
logger.raw(`\nForwarding: ${pc.cyan(webhookUrl)} ā ${pc.cyan(localUrl)}`);
|
|
@@ -20,6 +20,7 @@ export function startForwarding(apiUrl, hookId, port) {
|
|
|
20
20
|
const forwardHeaders = { ...headers };
|
|
21
21
|
delete forwardHeaders.host;
|
|
22
22
|
delete forwardHeaders.connection;
|
|
23
|
+
delete forwardHeaders['content-length'];
|
|
23
24
|
|
|
24
25
|
const queryString = new URLSearchParams(query || {}).toString();
|
|
25
26
|
const fullLocalUrl = queryString ? `${localUrl}?${queryString}` : localUrl;
|
|
@@ -41,7 +42,7 @@ export function startForwarding(apiUrl, hookId, port) {
|
|
|
41
42
|
};
|
|
42
43
|
|
|
43
44
|
es.onerror = () => {
|
|
44
|
-
logger.
|
|
45
|
+
logger.dim(`\n[Network] Connection dropped. Automatically reconnecting...`);
|
|
45
46
|
};
|
|
46
47
|
|
|
47
48
|
return es;
|