fbi-proxy 1.6.0 → 1.6.2
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 +75 -5
- package/dist/cli.js +11 -51
- package/package.json +2 -5
- 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 +4 -5
- package/ts/buildFbiProxy.ts +13 -5
- package/ts/cli.ts +3 -43
- package/Caddyfile +0 -47
- package/ts/downloadCaddy.ts +0 -24
package/README.md
CHANGED
|
@@ -2,6 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
FBI-Proxy provides easy HTTPS access to your local services with intelligent domain routing.
|
|
4
4
|
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
### Current Features ✅
|
|
8
|
+
|
|
9
|
+
- **Intelligent Domain Routing**: Multiple routing patterns for flexible service access
|
|
10
|
+
- Port-based routing (e.g., `3000.fbi.com` → `localhost:3000`)
|
|
11
|
+
- Host--Port routing (e.g., `api--3001.fbi.com` → `api:3001`)
|
|
12
|
+
- Subdomain routing with Host headers (e.g., `admin.app.fbi.com` → `app:80`)
|
|
13
|
+
- Direct host forwarding (e.g., `myserver.fbi.com` → `myserver:80`)
|
|
14
|
+
- **WebSocket Support**: Full WebSocket connection support for all routing patterns
|
|
15
|
+
- **High Performance**: Built with Rust for optimal performance and low resource usage
|
|
16
|
+
- **Easy Setup**: Simple one-command installation and startup
|
|
17
|
+
- **Docker Support**: Available as a Docker image for containerized deployments
|
|
18
|
+
- **Flexible Configuration**: Environment variables and CLI options for customization
|
|
19
|
+
- **Cross-Platform**: Works on macOS, Linux, and Windows
|
|
20
|
+
- **Integration Ready**: Compatible with reverse proxies like Caddy for HTTPS
|
|
21
|
+
|
|
22
|
+
## Roadmap
|
|
23
|
+
|
|
24
|
+
### Next Up 🚧
|
|
25
|
+
- [ ] **Configuration File Support** - YAML/JSON config for persistent routing rules
|
|
26
|
+
- [ ] **Access Control** - Domain filtering, host/port whitelisting
|
|
27
|
+
- [ ] **Request Logging** - Basic access logs for debugging
|
|
28
|
+
- [ ] **Health Checks** - Simple upstream service availability monitoring
|
|
29
|
+
|
|
30
|
+
### Future Improvements 🔮
|
|
31
|
+
- [ ] **Load Balancing** - Round-robin between multiple upstream targets
|
|
32
|
+
- [ ] **Metrics** - Basic statistics (requests, response times, errors)
|
|
33
|
+
- [ ] **Hot Reload** - Update configuration without restart
|
|
34
|
+
- [ ] **Custom Headers** - Add/modify headers for specific routes
|
|
35
|
+
|
|
5
36
|
## Routing Examples
|
|
6
37
|
|
|
7
38
|
```bash
|
|
@@ -32,13 +63,53 @@ bunx fbi-proxy
|
|
|
32
63
|
# expose to LAN
|
|
33
64
|
bunx fbi-proxy --host 0.0.0.0 --port=2432
|
|
34
65
|
|
|
35
|
-
# with
|
|
36
|
-
|
|
66
|
+
# run with docker
|
|
67
|
+
docker run --rm --name fbi-proxy --network=host snomiao/fbi-proxy
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Using with Caddy (Optional)
|
|
71
|
+
|
|
72
|
+
FBI-Proxy focuses on the core proxy functionality. For HTTPS and advanced routing, you can use Caddy as a reverse proxy:
|
|
73
|
+
|
|
74
|
+
### Install Caddy
|
|
37
75
|
|
|
38
|
-
|
|
39
|
-
|
|
76
|
+
```bash
|
|
77
|
+
# macOS
|
|
78
|
+
brew install caddy
|
|
79
|
+
|
|
80
|
+
# Ubuntu/Debian
|
|
81
|
+
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
|
|
82
|
+
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
|
|
83
|
+
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
|
|
84
|
+
sudo apt update
|
|
85
|
+
sudo apt install caddy
|
|
86
|
+
|
|
87
|
+
# Or download from https://caddyserver.com/download
|
|
40
88
|
```
|
|
41
89
|
|
|
90
|
+
### Caddyfile Example
|
|
91
|
+
|
|
92
|
+
Create a `Caddyfile` to route `*.fbi.com` to FBI-Proxy:
|
|
93
|
+
|
|
94
|
+
```caddyfile
|
|
95
|
+
*.fbi.com {
|
|
96
|
+
reverse_proxy localhost:2432
|
|
97
|
+
tls internal
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Run Both Services
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
# Terminal 1: Start FBI-Proxy
|
|
105
|
+
bunx fbi-proxy
|
|
106
|
+
|
|
107
|
+
# Terminal 2: Start Caddy
|
|
108
|
+
caddy run --config Caddyfile
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Now you can access your services via HTTPS at `https://*.fbi.com`!
|
|
112
|
+
|
|
42
113
|
## Development
|
|
43
114
|
|
|
44
115
|
```bash
|
|
@@ -56,7 +127,6 @@ bun run build && bun run start
|
|
|
56
127
|
|
|
57
128
|
- **Bun**: https://bun.sh/
|
|
58
129
|
- **Rust**: https://rustup.rs/
|
|
59
|
-
- **Caddy**: Auto-downloaded if not found
|
|
60
130
|
|
|
61
131
|
### Configuration
|
|
62
132
|
|
package/dist/cli.js
CHANGED
|
@@ -4989,6 +4989,7 @@ var yargs_default = Yargs;
|
|
|
4989
4989
|
|
|
4990
4990
|
// ts/buildFbiProxy.ts
|
|
4991
4991
|
import { existsSync } from "fs";
|
|
4992
|
+
import { chmod } from "fs/promises";
|
|
4992
4993
|
|
|
4993
4994
|
// ts/getProxyFilename.ts
|
|
4994
4995
|
function getFbiProxyFilename() {
|
|
@@ -5124,13 +5125,18 @@ async function getFbiProxyBinary({ rebuild = false } = {}) {
|
|
|
5124
5125
|
const release = "./release/" + binaryName;
|
|
5125
5126
|
const built = `./target/release/fbi-proxy${isWin ? ".exe" : ""}`;
|
|
5126
5127
|
if (!rebuild && existsSync(built)) {
|
|
5128
|
+
await chmod(built, 493).catch(() => {});
|
|
5127
5129
|
return built;
|
|
5128
5130
|
}
|
|
5129
|
-
if (!rebuild && existsSync(release))
|
|
5131
|
+
if (!rebuild && existsSync(release)) {
|
|
5132
|
+
await chmod(release, 493).catch(() => {});
|
|
5130
5133
|
return release;
|
|
5134
|
+
}
|
|
5131
5135
|
await $`cargo build --release`;
|
|
5132
|
-
if (existsSync(built))
|
|
5136
|
+
if (existsSync(built)) {
|
|
5137
|
+
await chmod(built, 493).catch(() => {});
|
|
5133
5138
|
return built;
|
|
5139
|
+
}
|
|
5134
5140
|
throw new Error("Oops, failed to build fbi-proxy binary. Please check your Rust setup.");
|
|
5135
5141
|
}
|
|
5136
5142
|
|
|
@@ -5217,38 +5223,15 @@ var $2 = Object.assign(dSpawn2(), {
|
|
|
5217
5223
|
cwd: (path) => dSpawn2({ cwd: path })
|
|
5218
5224
|
});
|
|
5219
5225
|
|
|
5220
|
-
// ts/downloadCaddy.ts
|
|
5221
|
-
import { existsSync as existsSync2 } from "fs";
|
|
5222
|
-
if (false) {}
|
|
5223
|
-
async function downloadCaddy() {
|
|
5224
|
-
const pwdCaddy = "./node_modules/.bin/caddy";
|
|
5225
|
-
if (existsSync2(pwdCaddy))
|
|
5226
|
-
return pwdCaddy;
|
|
5227
|
-
if (await $`caddy --version`.catch(() => false)) {
|
|
5228
|
-
return "caddy";
|
|
5229
|
-
}
|
|
5230
|
-
throw new Error("Failed to download Caddy. Please install Caddy manually or check your network connection.");
|
|
5231
|
-
}
|
|
5232
|
-
|
|
5233
5226
|
// ts/cli.ts
|
|
5234
|
-
|
|
5235
|
-
process.
|
|
5236
|
-
var argv = await yargs_default(hideBin(process.argv)).option("fbihost", {
|
|
5237
|
-
type: "string",
|
|
5238
|
-
default: "fbi.com",
|
|
5239
|
-
description: "Set the FBI host"
|
|
5240
|
-
}).option("caddy", {
|
|
5241
|
-
type: "boolean",
|
|
5242
|
-
default: false,
|
|
5243
|
-
description: "Start Caddy server"
|
|
5244
|
-
}).option("dev", {
|
|
5227
|
+
process.chdir(path.resolve(import.meta.dir, ".."));
|
|
5228
|
+
await yargs_default(hideBin(process.argv)).option("dev", {
|
|
5245
5229
|
alias: "d",
|
|
5246
5230
|
type: "boolean",
|
|
5247
5231
|
default: false,
|
|
5248
5232
|
description: "Run in development mode"
|
|
5249
5233
|
}).help().argv;
|
|
5250
5234
|
console.log("Preparing Binaries");
|
|
5251
|
-
var FBIHOST = argv.fbihost;
|
|
5252
5235
|
var FBIPROXY_PORT = String(await getPorts({ port: 2432 }));
|
|
5253
5236
|
var proxyProcess = await hotMemo(async () => {
|
|
5254
5237
|
const proxy = await getFbiProxyBinary();
|
|
@@ -5265,35 +5248,12 @@ var proxyProcess = await hotMemo(async () => {
|
|
|
5265
5248
|
});
|
|
5266
5249
|
return p;
|
|
5267
5250
|
});
|
|
5268
|
-
var caddyProcess = null;
|
|
5269
|
-
if (argv.caddy) {
|
|
5270
|
-
const caddy = await downloadCaddy();
|
|
5271
|
-
caddyProcess = await hotMemo(async () => {
|
|
5272
|
-
const p = $2.opt({
|
|
5273
|
-
env: {
|
|
5274
|
-
...process.env,
|
|
5275
|
-
FBIPROXY_PORT,
|
|
5276
|
-
FBIHOST
|
|
5277
|
-
}
|
|
5278
|
-
})`${caddy} run`.process;
|
|
5279
|
-
p.on("exit", (code) => {
|
|
5280
|
-
console.log(`Caddy exited with code ${code}`);
|
|
5281
|
-
process.exit(code || 0);
|
|
5282
|
-
});
|
|
5283
|
-
return p;
|
|
5284
|
-
});
|
|
5285
|
-
}
|
|
5286
5251
|
console.log("All services started successfully!");
|
|
5287
5252
|
console.log(`Proxy server PID: ${proxyProcess.pid}`);
|
|
5288
|
-
|
|
5289
|
-
console.log(`Caddy server PID: ${caddyProcess.pid}`);
|
|
5290
|
-
} else {
|
|
5291
|
-
console.log("Caddy server not started (use --caddy to start it)");
|
|
5292
|
-
}
|
|
5253
|
+
console.log(`Proxy server running on port: ${FBIPROXY_PORT}`);
|
|
5293
5254
|
var exit = () => {
|
|
5294
5255
|
console.log("Shutting down...");
|
|
5295
5256
|
proxyProcess?.kill?.();
|
|
5296
|
-
caddyProcess?.kill?.();
|
|
5297
5257
|
process.exit(0);
|
|
5298
5258
|
};
|
|
5299
5259
|
process.on("SIGINT", exit);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fbi-proxy",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "FBI-Proxy provides easy HTTPS access to your local services with intelligent domain routing",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"development-tools",
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"fbi-proxy": "dist/cli.js"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
|
-
"Caddyfile",
|
|
28
27
|
"dist",
|
|
29
28
|
"release",
|
|
30
29
|
"rs",
|
|
@@ -75,7 +74,5 @@
|
|
|
75
74
|
"bun --bun prettier --write"
|
|
76
75
|
]
|
|
77
76
|
},
|
|
78
|
-
"trustedDependencies": [
|
|
79
|
-
"@radically-straightforward/caddy"
|
|
80
|
-
]
|
|
77
|
+
"trustedDependencies": []
|
|
81
78
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/rs/fbi-proxy.rs
CHANGED
|
@@ -184,13 +184,12 @@ impl FBIProxy {
|
|
|
184
184
|
*req.uri_mut() = target_uri;
|
|
185
185
|
req.headers_mut()
|
|
186
186
|
.insert(HOST, HeaderValue::from_str(&new_host)?);
|
|
187
|
-
|
|
187
|
+
// Preserve content-encoding header to maintain compression
|
|
188
188
|
|
|
189
189
|
// Forward the request
|
|
190
190
|
match self.client.request(req).await {
|
|
191
|
-
Ok(
|
|
192
|
-
//
|
|
193
|
-
response.headers_mut().remove("content-encoding");
|
|
191
|
+
Ok(response) => {
|
|
192
|
+
// Preserve content-encoding header in response to maintain compression
|
|
194
193
|
let status = response.status();
|
|
195
194
|
info!(
|
|
196
195
|
"{} {}@{}{} {}",
|
|
@@ -361,7 +360,7 @@ pub async fn start_proxy_server_with_options(host: &str, port: u16, domain_filte
|
|
|
361
360
|
fn main() {
|
|
362
361
|
env_logger::init();
|
|
363
362
|
|
|
364
|
-
let matches = Command::new("
|
|
363
|
+
let matches = Command::new(env!("CARGO_CRATE_NAME"))
|
|
365
364
|
.version("0.1.1")
|
|
366
365
|
.about("A fast and flexible proxy server with smart host header parsing and WebSocket support")
|
|
367
366
|
.long_about(
|
package/ts/buildFbiProxy.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import fsp from "fs/promises";
|
|
2
1
|
import { existsSync } from "fs";
|
|
2
|
+
import { chmod } from "fs/promises";
|
|
3
3
|
import { getFbiProxyFilename } from "./getProxyFilename";
|
|
4
|
-
import { copyFile } from "fs/promises";
|
|
5
4
|
import { $ } from "./dSpawn";
|
|
6
|
-
import { mkdir } from "fs/promises";
|
|
7
5
|
|
|
8
6
|
if (import.meta.main) {
|
|
9
7
|
await getFbiProxyBinary();
|
|
@@ -24,15 +22,25 @@ export async function getFbiProxyBinary({ rebuild = false } = {}) {
|
|
|
24
22
|
|
|
25
23
|
// return built if exists
|
|
26
24
|
if (!rebuild && existsSync(built)) {
|
|
25
|
+
// Ensure the binary has execute permissions
|
|
26
|
+
await chmod(built, 0o755).catch(() => {}); // Ignore errors if we can't change permissions
|
|
27
27
|
return built;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
// return release if exists
|
|
31
|
-
if (!rebuild && existsSync(release))
|
|
31
|
+
if (!rebuild && existsSync(release)) {
|
|
32
|
+
// Ensure the binary has execute permissions
|
|
33
|
+
await chmod(release, 0o755).catch(() => {}); // Ignore errors if we can't change permissions
|
|
34
|
+
return release;
|
|
35
|
+
}
|
|
32
36
|
|
|
33
37
|
// build and return built target
|
|
34
38
|
await $`cargo build --release`;
|
|
35
|
-
if (existsSync(built))
|
|
39
|
+
if (existsSync(built)) {
|
|
40
|
+
// Ensure the binary has execute permissions
|
|
41
|
+
await chmod(built, 0o755).catch(() => {}); // Ignore errors if we can't change permissions
|
|
42
|
+
return built;
|
|
43
|
+
}
|
|
36
44
|
|
|
37
45
|
throw new Error(
|
|
38
46
|
"Oops, failed to build fbi-proxy binary. Please check your Rust setup.",
|
package/ts/cli.ts
CHANGED
|
@@ -6,23 +6,11 @@ import yargs from "yargs";
|
|
|
6
6
|
import { hideBin } from "yargs/helpers";
|
|
7
7
|
import { getFbiProxyBinary } from "./buildFbiProxy";
|
|
8
8
|
import { $ } from "./dSpawn";
|
|
9
|
-
import { downloadCaddy } from "./downloadCaddy";
|
|
10
|
-
import { execa } from "execa";
|
|
11
9
|
|
|
12
|
-
process.chdir(path.resolve(
|
|
10
|
+
process.chdir(path.resolve(import.meta.dir, "..")); // Change to project root directory
|
|
13
11
|
|
|
14
12
|
// Parse command line arguments with yargs
|
|
15
|
-
|
|
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
|
-
})
|
|
13
|
+
await yargs(hideBin(process.argv))
|
|
26
14
|
.option("dev", {
|
|
27
15
|
alias: "d",
|
|
28
16
|
type: "boolean",
|
|
@@ -33,7 +21,6 @@ const argv = await yargs(hideBin(process.argv))
|
|
|
33
21
|
|
|
34
22
|
console.log("Preparing Binaries");
|
|
35
23
|
|
|
36
|
-
const FBIHOST = argv.fbihost;
|
|
37
24
|
const FBIPROXY_PORT = String(await getPort({ port: 2432 }));
|
|
38
25
|
|
|
39
26
|
const proxyProcess = await hotMemo(async () => {
|
|
@@ -53,40 +40,13 @@ const proxyProcess = await hotMemo(async () => {
|
|
|
53
40
|
return p;
|
|
54
41
|
});
|
|
55
42
|
|
|
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;
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
43
|
console.log("All services started successfully!");
|
|
78
|
-
// show process pids
|
|
79
44
|
console.log(`Proxy server PID: ${proxyProcess.pid}`);
|
|
80
|
-
|
|
81
|
-
console.log(`Caddy server PID: ${caddyProcess.pid}`);
|
|
82
|
-
} else {
|
|
83
|
-
console.log("Caddy server not started (use --caddy to start it)");
|
|
84
|
-
}
|
|
45
|
+
console.log(`Proxy server running on port: ${FBIPROXY_PORT}`);
|
|
85
46
|
|
|
86
47
|
const exit = () => {
|
|
87
48
|
console.log("Shutting down...");
|
|
88
49
|
proxyProcess?.kill?.();
|
|
89
|
-
caddyProcess?.kill?.();
|
|
90
50
|
process.exit(0);
|
|
91
51
|
};
|
|
92
52
|
process.on("SIGINT", exit);
|
package/Caddyfile
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
admin off
|
|
3
|
-
# TODO: add ondemand tls endpoint to cli.ts
|
|
4
|
-
# - [Global options (Caddyfile) — Caddy Documentation]( https://caddyserver.com/docs/caddyfile/options#on-demand-tls )
|
|
5
|
-
# make a endpoint to handle /CHECK_TLS?domain=..., and return 200 if domain is valid
|
|
6
|
-
#
|
|
7
|
-
# on_demand_tls {
|
|
8
|
-
# ask http://localhost:{$PROX}/CHECK_TLS
|
|
9
|
-
# }
|
|
10
|
-
servers {
|
|
11
|
-
trusted_proxies static private_ranges
|
|
12
|
-
trusted_proxies_strict
|
|
13
|
-
}
|
|
14
|
-
# auto_https disable_redirects
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
# unwrap all https
|
|
18
|
-
http://*, http://*.*, http://*.*.*, http://*.*.*.*, https://*, https://*.*, https://*.*.*, https://*.*.*.* {
|
|
19
|
-
tls internal {
|
|
20
|
-
on_demand
|
|
21
|
-
}
|
|
22
|
-
# match **.fbi.com use regex match against to host
|
|
23
|
-
@subhost {
|
|
24
|
-
header_regexp subhost Host ^((?:(.+)\.)?{$FBIHOST:fbi.com})$
|
|
25
|
-
}
|
|
26
|
-
@fullhost {
|
|
27
|
-
header_regexp fullhost Host ^(.+)$
|
|
28
|
-
}
|
|
29
|
-
# debug
|
|
30
|
-
# handle @subhost {
|
|
31
|
-
# respond "https://{re.subhost.1}{uri} => http://{re.subhost.2}{uri}"
|
|
32
|
-
# }
|
|
33
|
-
|
|
34
|
-
reverse_proxy @subhost :{$FBIPROXY_PORT:24306} {
|
|
35
|
-
# strip the fbi.com part from the host
|
|
36
|
-
header_up Host {re.subhost.2}
|
|
37
|
-
# header_up X-Forwarded-Host {re.subhost.1}
|
|
38
|
-
}
|
|
39
|
-
reverse_proxy @fullhost :{$FBIPROXY_PORT:24306} {
|
|
40
|
-
header_up Host {re.fullhost.1}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
# 3000.amd.fbi.com => *.amd.fbi.com goes to amd.fbi.com with 3000.localhost host
|
|
44
|
-
|
|
45
|
-
# for all other hosts, 404
|
|
46
|
-
# respond 404
|
|
47
|
-
}
|
package/ts/downloadCaddy.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "fs";
|
|
2
|
-
import { $ } from "./dSpawn";
|
|
3
|
-
|
|
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
|
-
}
|
|
10
|
-
|
|
11
|
-
export async function downloadCaddy() {
|
|
12
|
-
// use pwdCaddy if already downloaded
|
|
13
|
-
const pwdCaddy = "./node_modules/.bin/caddy";
|
|
14
|
-
if (existsSync(pwdCaddy)) return pwdCaddy;
|
|
15
|
-
|
|
16
|
-
// // or use system caddy if installed, run `caddy --version` to check
|
|
17
|
-
if (await $`caddy --version`.catch(() => false)) {
|
|
18
|
-
return "caddy";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
throw new Error(
|
|
22
|
-
"Failed to download Caddy. Please install Caddy manually or check your network connection.",
|
|
23
|
-
);
|
|
24
|
-
}
|