fbi-proxy 1.4.0 → 1.6.0
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 +48 -149
- package/dist/cli.js +5304 -0
- package/package.json +57 -48
- package/release/fbi-proxy-linux-arm64 +0 -0
- package/release/fbi-proxy-linux-x64 +0 -0
- package/release/fbi-proxy-macos-arm64 +0 -0
- package/release/fbi-proxy-macos-x64 +0 -0
- package/release/fbi-proxy-windows-arm64.exe +0 -0
- package/release/fbi-proxy-windows-x64.exe +0 -0
- package/rs/fbi-proxy.rs +461 -0
- package/ts/buildFbiProxy.ts +11 -5
- package/ts/cli.ts +53 -49
- package/ts/{dRun.ts → dSpawn.ts} +9 -8
- package/ts/downloadCaddy.ts +15 -22
- package/ts/getProxyFilename.ts +1 -1
package/ts/cli.ts
CHANGED
|
@@ -1,49 +1,43 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import getPort from "get-port";
|
|
3
3
|
import hotMemo from "hot-memo";
|
|
4
|
-
import minimist from "minimist";
|
|
5
4
|
import path from "path";
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
5
|
+
import yargs from "yargs";
|
|
6
|
+
import { hideBin } from "yargs/helpers";
|
|
7
|
+
import { getFbiProxyBinary } from "./buildFbiProxy";
|
|
8
|
+
import { $ } from "./dSpawn";
|
|
9
9
|
import { downloadCaddy } from "./downloadCaddy";
|
|
10
|
+
import { execa } from "execa";
|
|
10
11
|
|
|
11
12
|
process.chdir(path.resolve(__dirname, "..")); // Change to project root directory
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
// Parse command line arguments with yargs
|
|
15
|
+
const argv = await yargs(hideBin(process.argv))
|
|
16
|
+
.option("fbihost", {
|
|
17
|
+
type: "string",
|
|
18
|
+
default: "fbi.com",
|
|
19
|
+
description: "Set the FBI host",
|
|
20
|
+
})
|
|
21
|
+
.option("caddy", {
|
|
22
|
+
type: "boolean",
|
|
23
|
+
default: false,
|
|
24
|
+
description: "Start Caddy server",
|
|
25
|
+
})
|
|
26
|
+
.option("dev", {
|
|
27
|
+
alias: "d",
|
|
28
|
+
type: "boolean",
|
|
29
|
+
default: false,
|
|
30
|
+
description: "Run in development mode",
|
|
31
|
+
})
|
|
32
|
+
.help().argv;
|
|
19
33
|
|
|
20
|
-
console.log("
|
|
34
|
+
console.log("Preparing Binaries");
|
|
21
35
|
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
default: {
|
|
25
|
-
dev: false,
|
|
26
|
-
d: false,
|
|
27
|
-
fbihost: "fbi.com", // Default FBI host
|
|
28
|
-
},
|
|
29
|
-
alias: {
|
|
30
|
-
dev: "d",
|
|
31
|
-
},
|
|
32
|
-
boolean: ["dev", "d", "help"],
|
|
33
|
-
});
|
|
34
|
-
// console.log(argv);
|
|
35
|
-
if (argv.help) {
|
|
36
|
-
console.log(`Usage: fbi-proxy [options]
|
|
37
|
-
Options:
|
|
38
|
-
--help Show this help message
|
|
39
|
-
--fbihost Set the FBI host (default: fbi.com)
|
|
40
|
-
`);
|
|
41
|
-
process.exit(0);
|
|
42
|
-
}
|
|
36
|
+
const FBIHOST = argv.fbihost;
|
|
37
|
+
const FBIPROXY_PORT = String(await getPort({ port: 2432 }));
|
|
43
38
|
|
|
44
|
-
const FBIHOST = argv.fbihost || "fbi.com"; // Default FBI host
|
|
45
|
-
const FBIPROXY_PORT = String(await getPort({ port: 24306 }));
|
|
46
39
|
const proxyProcess = await hotMemo(async () => {
|
|
40
|
+
const proxy = await getFbiProxyBinary();
|
|
47
41
|
console.log("Starting Rust proxy server");
|
|
48
42
|
const p = $.opt({
|
|
49
43
|
env: {
|
|
@@ -59,25 +53,35 @@ const proxyProcess = await hotMemo(async () => {
|
|
|
59
53
|
return p;
|
|
60
54
|
});
|
|
61
55
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
56
|
+
let caddyProcess: any = null;
|
|
57
|
+
|
|
58
|
+
// Only start Caddy if --caddy flag is passed
|
|
59
|
+
if (argv.caddy) {
|
|
60
|
+
const caddy = await downloadCaddy();
|
|
61
|
+
caddyProcess = await hotMemo(async () => {
|
|
62
|
+
const p = $.opt({
|
|
63
|
+
env: {
|
|
64
|
+
...process.env,
|
|
65
|
+
FBIPROXY_PORT, // Rust proxy server port
|
|
66
|
+
FBIHOST,
|
|
67
|
+
},
|
|
68
|
+
})`${caddy} run`.process;
|
|
69
|
+
p.on("exit", (code) => {
|
|
70
|
+
console.log(`Caddy exited with code ${code}`);
|
|
71
|
+
process.exit(code || 0);
|
|
72
|
+
});
|
|
73
|
+
return p;
|
|
73
74
|
});
|
|
74
|
-
|
|
75
|
-
});
|
|
75
|
+
}
|
|
76
76
|
|
|
77
|
-
console.log("
|
|
77
|
+
console.log("All services started successfully!");
|
|
78
78
|
// show process pids
|
|
79
79
|
console.log(`Proxy server PID: ${proxyProcess.pid}`);
|
|
80
|
-
|
|
80
|
+
if (caddyProcess) {
|
|
81
|
+
console.log(`Caddy server PID: ${caddyProcess.pid}`);
|
|
82
|
+
} else {
|
|
83
|
+
console.log("Caddy server not started (use --caddy to start it)");
|
|
84
|
+
}
|
|
81
85
|
|
|
82
86
|
const exit = () => {
|
|
83
87
|
console.log("Shutting down...");
|
package/ts/{dRun.ts → dSpawn.ts}
RENAMED
|
@@ -15,17 +15,18 @@ type DRunProc = Promise<{
|
|
|
15
15
|
process: ChildProcess;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const dSpawn = ({
|
|
19
19
|
cwd = process.cwd(),
|
|
20
20
|
env = process.env as Record<string, string>,
|
|
21
21
|
} = {}) =>
|
|
22
22
|
tsaComposer(
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
// slot is un dividable
|
|
24
|
+
(slot: string | { raw: string }) =>
|
|
25
|
+
typeof slot === "string"
|
|
25
26
|
? {
|
|
26
|
-
raw: String(
|
|
27
|
+
raw: String(slot), // todo: escape quotes
|
|
27
28
|
}
|
|
28
|
-
:
|
|
29
|
+
: slot,
|
|
29
30
|
(...slots): DRunProc => {
|
|
30
31
|
try {
|
|
31
32
|
// TODO: parse slots for quotes
|
|
@@ -106,7 +107,7 @@ const dRun = ({
|
|
|
106
107
|
},
|
|
107
108
|
);
|
|
108
109
|
|
|
109
|
-
export const $ = Object.assign(
|
|
110
|
-
opt:
|
|
111
|
-
cwd: (path: string) =>
|
|
110
|
+
export const $ = Object.assign(dSpawn(), {
|
|
111
|
+
opt: dSpawn,
|
|
112
|
+
cwd: (path: string) => dSpawn({ cwd: path }),
|
|
112
113
|
});
|
package/ts/downloadCaddy.ts
CHANGED
|
@@ -1,31 +1,24 @@
|
|
|
1
1
|
import { existsSync } from "fs";
|
|
2
|
-
import
|
|
3
|
-
import { $ } from "./dRun";
|
|
2
|
+
import { $ } from "./dSpawn";
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
const
|
|
4
|
+
if (import.meta.main) {
|
|
5
|
+
// if this file is run directly, download caddy
|
|
6
|
+
const caddy = await downloadCaddy();
|
|
7
|
+
console.log(`Caddy downloaded to: ${caddy}`);
|
|
8
|
+
process.exit(0);
|
|
9
|
+
}
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
export async function downloadCaddy() {
|
|
12
|
+
// use pwdCaddy if already downloaded
|
|
13
|
+
const pwdCaddy = "./node_modules/.bin/caddy";
|
|
10
14
|
if (existsSync(pwdCaddy)) return pwdCaddy;
|
|
11
15
|
|
|
12
|
-
// or use system caddy if installed, run `caddy --version` to check
|
|
16
|
+
// // or use system caddy if installed, run `caddy --version` to check
|
|
13
17
|
if (await $`caddy --version`.catch(() => false)) {
|
|
14
18
|
return "caddy";
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// @ts-ignore
|
|
22
|
-
await import("../node_modules/caddy-baron/index.mjs");
|
|
23
|
-
|
|
24
|
-
if (!existsSync(pwdCaddy))
|
|
25
|
-
throw new Error(
|
|
26
|
-
"Failed to download Caddy. Please install Caddy manually or check your network connection.",
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return pwdCaddy;
|
|
31
|
-
};
|
|
21
|
+
throw new Error(
|
|
22
|
+
"Failed to download Caddy. Please install Caddy manually or check your network connection.",
|
|
23
|
+
);
|
|
24
|
+
}
|
package/ts/getProxyFilename.ts
CHANGED