-
Notifications
You must be signed in to change notification settings - Fork 137
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
Showing
2 changed files
with
32 additions
and
26 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,41 @@ | ||
#!/usr/bin/env node | ||
|
||
import { program } from 'commander' | ||
import { readFile } from 'node:fs/promises' | ||
import Client from '../index.js' | ||
import { program } from "commander"; | ||
import { readFile } from "node:fs/promises"; | ||
import Client from "../index.js"; | ||
|
||
const { version } = JSON.parse(await readFile(new URL('../package.json', import.meta.url))) | ||
const { version } = JSON.parse( | ||
await readFile(new URL("../package.json", import.meta.url)), | ||
); | ||
|
||
program | ||
.version(version, '-v, --version') | ||
.usage('[options]') | ||
.option('-u, --url <url>', 'URL of the webhook proxy service. Default: https://smee.io/new') | ||
.option('-t, --target <target>', 'Full URL (including protocol and path) of the target service the events will forwarded to. Default: http://127.0.0.1:PORT/PATH') | ||
.option('-p, --port <n>', 'Local HTTP server port', process.env.PORT || 3000) | ||
.option('-P, --path <path>', 'URL path to post proxied requests to`', '/') | ||
.parse(process.argv) | ||
|
||
const opts = program.opts() | ||
|
||
const { | ||
target = `http://127.0.0.1:${opts.port}${opts.path}` | ||
} = opts | ||
|
||
async function setup () { | ||
let source = opts.url | ||
.version(version, "-v, --version") | ||
.usage("[options]") | ||
.option( | ||
"-u, --url <url>", | ||
"URL of the webhook proxy service. Default: https://smee.io/new", | ||
) | ||
.option( | ||
"-t, --target <target>", | ||
"Full URL (including protocol and path) of the target service the events will forwarded to. Default: http://127.0.0.1:PORT/PATH", | ||
) | ||
.option("-p, --port <n>", "Local HTTP server port", process.env.PORT || 3000) | ||
.option("-P, --path <path>", "URL path to post proxied requests to`", "/") | ||
.parse(process.argv); | ||
|
||
const opts = program.opts(); | ||
|
||
const { target = `http://127.0.0.1:${opts.port}${opts.path}` } = opts; | ||
|
||
async function setup() { | ||
let source = opts.url; | ||
|
||
if (!source) { | ||
source = await Client.createChannel() | ||
source = await Client.createChannel(); | ||
} | ||
|
||
const client = new Client({ source, target }) | ||
client.start() | ||
const client = new Client({ source, target }); | ||
client.start(); | ||
} | ||
|
||
setup() | ||
setup(); |
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