mirror of
https://github.com/yusing/godoxy.git
synced 2025-07-11 16:44:03 +02:00
changed env GOPROXY_*_PORT to GOPROXY_*_ADDR, changed api server default to listen on localhost only, readme update
This commit is contained in:
parent
d9fd399e43
commit
96bce79e4b
6 changed files with 31 additions and 37 deletions
16
README.md
16
README.md
|
@ -76,13 +76,13 @@ A lightweight, easy-to-use, and [performant](docs/benchmark_result.md) reverse p
|
||||||
|
|
||||||
### Environment variables
|
### Environment variables
|
||||||
|
|
||||||
| Environment Variable | Description | Default | Values |
|
| Environment Variable | Description | Default | Values |
|
||||||
| ------------------------------ | ----------------------------- | ------- | ------- |
|
| ------------------------------ | ------------------------------------------- | ---------------- | ------------- |
|
||||||
| `GOPROXY_NO_SCHEMA_VALIDATION` | disable schema validation | `false` | boolean |
|
| `GOPROXY_NO_SCHEMA_VALIDATION` | disable schema validation | `false` | boolean |
|
||||||
| `GOPROXY_DEBUG` | enable debug behaviors | `false` | boolean |
|
| `GOPROXY_DEBUG` | enable debug behaviors | `false` | boolean |
|
||||||
| `GOPROXY_HTTP_PORT` | http server port | `80` | integer |
|
| `GOPROXY_HTTP_ADDR` | http server listening address | `:80` | `[host]:port` |
|
||||||
| `GOPROXY_HTTPS_PORT` | http server port (if enabled) | `443` | integer |
|
| `GOPROXY_HTTPS_ADDR` | https server listening address (if enabled) | `:443` | `[host]:port` |
|
||||||
| `GOPROXY_API_PORT` | api server port | `8888` | integer |
|
| `GOPROXY_API_ADDR` | api server listening address | `127.0.0.1:8888` | `[host]:port` |
|
||||||
|
|
||||||
### Use JSON Schema in VSCode
|
### Use JSON Schema in VSCode
|
||||||
|
|
||||||
|
@ -126,8 +126,6 @@ See [providers.example.yml](providers.example.yml) for examples
|
||||||
|
|
||||||
## Known issues
|
## Known issues
|
||||||
|
|
||||||
- Cert "renewal" is actually obtaining a new cert instead of renewing the existing one
|
|
||||||
|
|
||||||
- `autocert` config is not hot-reloadable
|
- `autocert` config is not hot-reloadable
|
||||||
|
|
||||||
[🔼Back to top](#table-of-content)
|
[🔼Back to top](#table-of-content)
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
[](https://sonarcloud.io/summary/new_code?id=yusing_go-proxy)
|
[](https://sonarcloud.io/summary/new_code?id=yusing_go-proxy)
|
||||||
[](https://sonarcloud.io/summary/new_code?id=yusing_go-proxy)
|
[](https://sonarcloud.io/summary/new_code?id=yusing_go-proxy)
|
||||||
|
|
||||||
一個輕量化、易用且[高效](docs/benchmark_result.md)的反向代理工具
|
一個輕量化、易用且[高效](docs/benchmark_result.md)的反向代理和端口轉發工具
|
||||||
|
|
||||||
## 目錄
|
## 目錄
|
||||||
|
|
||||||
|
@ -72,10 +72,13 @@
|
||||||
|
|
||||||
### 環境變量
|
### 環境變量
|
||||||
|
|
||||||
| 環境變量 | 描述 | 默認 | 值 |
|
| 環境變量 | 描述 | 默認 | 格式 |
|
||||||
| ------------------------------ | ---------------- | ------- | ------- |
|
| ------------------------------ | ---------------- | ---------------- | ------------- |
|
||||||
| `GOPROXY_NO_SCHEMA_VALIDATION` | 禁用 schema 驗證 | `false` | boolean |
|
| `GOPROXY_NO_SCHEMA_VALIDATION` | 禁用 schema 驗證 | `false` | boolean |
|
||||||
| `GOPROXY_DEBUG` | 啟用調試輸出 | `false` | boolean |
|
| `GOPROXY_DEBUG` | 啟用調試輸出 | `false` | boolean |
|
||||||
|
| `GOPROXY_HTTP_ADDR` | http 收聽地址 | `:80` | `[host]:port` |
|
||||||
|
| `GOPROXY_HTTPS_ADDR` | https 收聽地址 | `:443` | `[host]:port` |
|
||||||
|
| `GOPROXY_API_ADDR` | api 收聽地址 | `127.0.0.1:8888` | `[host]:port` |
|
||||||
|
|
||||||
### VSCode 中使用 JSON Schema
|
### VSCode 中使用 JSON Schema
|
||||||
|
|
||||||
|
@ -119,8 +122,6 @@ providers:
|
||||||
|
|
||||||
## 已知問題
|
## 已知問題
|
||||||
|
|
||||||
- 證書“更新”實際上是獲取新證書而不是更新現有證書
|
|
||||||
|
|
||||||
- `autocert` 配置不能熱重載
|
- `autocert` 配置不能熱重載
|
||||||
|
|
||||||
[🔼 返回頂部](#目錄)
|
[🔼 返回頂部](#目錄)
|
||||||
|
|
|
@ -36,7 +36,7 @@ func IsStreamHealthy(scheme, address string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReloadServer() E.NestedError {
|
func ReloadServer() E.NestedError {
|
||||||
resp, err := HttpClient.Post(fmt.Sprintf("http://localhost%v/reload", common.APIHTTPPort), "", nil)
|
resp, err := HttpClient.Post(fmt.Sprintf("http://localhost%v/reload", common.APIHTTPAddr), "", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return E.From(err)
|
return E.From(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,9 @@ import (
|
||||||
var (
|
var (
|
||||||
NoSchemaValidation = getEnvBool("GOPROXY_NO_SCHEMA_VALIDATION")
|
NoSchemaValidation = getEnvBool("GOPROXY_NO_SCHEMA_VALIDATION")
|
||||||
IsDebug = getEnvBool("GOPROXY_DEBUG")
|
IsDebug = getEnvBool("GOPROXY_DEBUG")
|
||||||
ProxyHTTPPort = ":" + getEnv("GOPROXY_HTTP_PORT", "80")
|
ProxyHTTPAddr = getEnv("GOPROXY_HTTP_ADDR", ":80")
|
||||||
ProxyHTTPSPort = ":" + getEnv("GOPROXY_HTTPS_PORT", "443")
|
ProxyHTTPSAddr = getEnv("GOPROXY_HTTPS_ADDR", ":443")
|
||||||
APIHTTPPort = ":" + getEnv("GOPROXY_API_PORT", "8888")
|
APIHTTPAddr = getEnv("GOPROXY_API_ADDR", "127.0.0.1:8888")
|
||||||
)
|
)
|
||||||
|
|
||||||
func getEnvBool(key string) bool {
|
func getEnvBool(key string) bool {
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"runtime"
|
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
@ -27,8 +26,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
||||||
|
|
||||||
args := common.GetArgs()
|
args := common.GetArgs()
|
||||||
l := logrus.WithField("module", "main")
|
l := logrus.WithField("module", "main")
|
||||||
|
|
||||||
|
@ -136,15 +133,15 @@ func main() {
|
||||||
proxyServer := server.InitProxyServer(server.Options{
|
proxyServer := server.InitProxyServer(server.Options{
|
||||||
Name: "proxy",
|
Name: "proxy",
|
||||||
CertProvider: autocert,
|
CertProvider: autocert,
|
||||||
HTTPPort: common.ProxyHTTPPort,
|
HTTPAddr: common.ProxyHTTPAddr,
|
||||||
HTTPSPort: common.ProxyHTTPSPort,
|
HTTPSAddr: common.ProxyHTTPSAddr,
|
||||||
Handler: http.HandlerFunc(R.ProxyHandler),
|
Handler: http.HandlerFunc(R.ProxyHandler),
|
||||||
RedirectToHTTPS: cfg.Value().RedirectToHTTPS,
|
RedirectToHTTPS: cfg.Value().RedirectToHTTPS,
|
||||||
})
|
})
|
||||||
apiServer := server.InitAPIServer(server.Options{
|
apiServer := server.InitAPIServer(server.Options{
|
||||||
Name: "api",
|
Name: "api",
|
||||||
CertProvider: autocert,
|
CertProvider: autocert,
|
||||||
HTTPPort: common.APIHTTPPort,
|
HTTPAddr: common.APIHTTPAddr,
|
||||||
Handler: api.NewHandler(cfg),
|
Handler: api.NewHandler(cfg),
|
||||||
RedirectToHTTPS: cfg.Value().RedirectToHTTPS,
|
RedirectToHTTPS: cfg.Value().RedirectToHTTPS,
|
||||||
})
|
})
|
||||||
|
|
|
@ -22,11 +22,9 @@ type server struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Name string
|
Name string
|
||||||
// port (with leading colon)
|
HTTPAddr string
|
||||||
HTTPPort string
|
HTTPSAddr string
|
||||||
// port (with leading colon)
|
|
||||||
HTTPSPort string
|
|
||||||
CertProvider *autocert.Provider
|
CertProvider *autocert.Provider
|
||||||
RedirectToHTTPS bool
|
RedirectToHTTPS bool
|
||||||
Handler http.Handler
|
Handler http.Handler
|
||||||
|
@ -55,22 +53,22 @@ func NewServer(opt Options) (s *server) {
|
||||||
certAvailable = err == nil
|
certAvailable = err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if certAvailable && opt.RedirectToHTTPS && opt.HTTPSPort != "" {
|
if certAvailable && opt.RedirectToHTTPS && opt.HTTPSAddr != "" {
|
||||||
httpHandler = redirectToTLSHandler(opt.HTTPSPort)
|
httpHandler = redirectToTLSHandler(opt.HTTPSAddr)
|
||||||
} else {
|
} else {
|
||||||
httpHandler = opt.Handler
|
httpHandler = opt.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
if opt.HTTPPort != "" {
|
if opt.HTTPAddr != "" {
|
||||||
httpSer = &http.Server{
|
httpSer = &http.Server{
|
||||||
Addr: opt.HTTPPort,
|
Addr: opt.HTTPAddr,
|
||||||
Handler: httpHandler,
|
Handler: httpHandler,
|
||||||
ErrorLog: logger,
|
ErrorLog: logger,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if certAvailable && opt.HTTPSPort != "" {
|
if certAvailable && opt.HTTPSAddr != "" {
|
||||||
httpsSer = &http.Server{
|
httpsSer = &http.Server{
|
||||||
Addr: opt.HTTPSPort,
|
Addr: opt.HTTPSAddr,
|
||||||
Handler: opt.Handler,
|
Handler: opt.Handler,
|
||||||
ErrorLog: logger,
|
ErrorLog: logger,
|
||||||
TLSConfig: &tls.Config{
|
TLSConfig: &tls.Config{
|
||||||
|
|
Loading…
Add table
Reference in a new issue