@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process'
22import { chmodSync , createWriteStream , existsSync , mkdirSync , unlinkSync , writeFileSync } from 'node:fs'
33import { readFile , unlink , writeFile } from 'node:fs/promises'
44import { platform } from 'node:os'
5+ import { join } from 'node:path'
56import process from 'node:process'
67import { got } from 'got-cjs'
78import { HttpProxyAgent } from 'http-proxy-agent'
@@ -38,7 +39,7 @@ export async function download(): Promise<string> {
3839 if ( ! support )
3940 return reject ( new Error ( 'not support' ) )
4041
41- const dowmloadLink = `https://caddyserver.com/api/download?os=${ support . platform } &arch=${ support . arch } `
42+ const dowmloadLink = `https://caddyserver.com/api/download?os=${ support . platform } &arch=${ support . arch } &p=github.com%2Fcaddyserver%2Fforwardproxy `
4243
4344 existsSync ( caddyPath ) && unlinkSync ( caddyPath )
4445
@@ -143,7 +144,7 @@ export class CaddyInstant {
143144 debug
144145 auto_https disable_redirects
145146}
146-
147+
147148`
148149 await writeFile ( caddyFilePath , contet )
149150 this . caddyfile = contet
@@ -214,6 +215,28 @@ ${target.split(':')[0]}${https ? '' : ':80'} {
214215 }
215216}
216217
218+ :7601 {
219+ root * "${ join (
220+ process . platform === 'win32'
221+ ? `${ process . env . AppData ! } /Caddy`
222+ : `${ process . env . HOME ! } /Library/Application Support/Caddy` ,
223+ './pki/authorities/local' ,
224+ ) } "
225+ file_server browse
226+ }
227+
228+ # 正向代理配置
229+ :7600 {
230+ bind 0.0.0.0
231+
232+ forward_proxy {
233+ hide_ip
234+ hide_via
235+ acl {
236+ allow all
237+ }
238+ }
239+ }
217240`
218241
219242 await this . writeCaddyfile ( )
@@ -287,7 +310,7 @@ ${target.split(':')[0]}${https ? '' : ':80'} {
287310
288311 if ( ! this . locked ) {
289312 this . _caddyChild = process . platform !== 'win32'
290- ? spawn ( 'sudo' , [ '-E' , caddyPath , 'run' , '--config' , caddyFilePath , '--watch' ] )
313+ ? spawn ( 'sudo' , [ '-E' , caddyPath , 'run' , '--config' , caddyFilePath , '--watch' , '--environ' ] )
291314 : spawn ( caddyPath , [ 'run' , '--config' , caddyFilePath , '--watch' ] )
292315
293316 lockfile . lockSync ( caddyLockFilePath )
0 commit comments