mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-19 20:32:35 +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 Variable | Description | Default | Values |
|
||||
| ------------------------------ | ----------------------------- | ------- | ------- |
|
||||
| `GOPROXY_NO_SCHEMA_VALIDATION` | disable schema validation | `false` | boolean |
|
||||
| `GOPROXY_DEBUG` | enable debug behaviors | `false` | boolean |
|
||||
| `GOPROXY_HTTP_PORT` | http server port | `80` | integer |
|
||||
| `GOPROXY_HTTPS_PORT` | http server port (if enabled) | `443` | integer |
|
||||
| `GOPROXY_API_PORT` | api server port | `8888` | integer |
|
||||
| Environment Variable | Description | Default | Values |
|
||||
| ------------------------------ | ------------------------------------------- | ---------------- | ------------- |
|
||||
| `GOPROXY_NO_SCHEMA_VALIDATION` | disable schema validation | `false` | boolean |
|
||||
| `GOPROXY_DEBUG` | enable debug behaviors | `false` | boolean |
|
||||
| `GOPROXY_HTTP_ADDR` | http server listening address | `:80` | `[host]:port` |
|
||||
| `GOPROXY_HTTPS_ADDR` | https server listening address (if enabled) | `:443` | `[host]:port` |
|
||||
| `GOPROXY_API_ADDR` | api server listening address | `127.0.0.1:8888` | `[host]:port` |
|
||||
|
||||
### Use JSON Schema in VSCode
|
||||
|
||||
|
@ -126,8 +126,6 @@ See [providers.example.yml](providers.example.yml) for examples
|
|||
|
||||
## Known issues
|
||||
|
||||
- Cert "renewal" is actually obtaining a new cert instead of renewing the existing one
|
||||
|
||||
- `autocert` config is not hot-reloadable
|
||||
|
||||
[🔼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)
|
||||
|
||||
一個輕量化、易用且[高效](docs/benchmark_result.md)的反向代理工具
|
||||
一個輕量化、易用且[高效](docs/benchmark_result.md)的反向代理和端口轉發工具
|
||||
|
||||
## 目錄
|
||||
|
||||
|
@ -72,10 +72,13 @@
|
|||
|
||||
### 環境變量
|
||||
|
||||
| 環境變量 | 描述 | 默認 | 值 |
|
||||
| ------------------------------ | ---------------- | ------- | ------- |
|
||||
| `GOPROXY_NO_SCHEMA_VALIDATION` | 禁用 schema 驗證 | `false` | boolean |
|
||||
| `GOPROXY_DEBUG` | 啟用調試輸出 | `false` | boolean |
|
||||
| 環境變量 | 描述 | 默認 | 格式 |
|
||||
| ------------------------------ | ---------------- | ---------------- | ------------- |
|
||||
| `GOPROXY_NO_SCHEMA_VALIDATION` | 禁用 schema 驗證 | `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
|
||||
|
||||
|
@ -119,8 +122,6 @@ providers:
|
|||
|
||||
## 已知問題
|
||||
|
||||
- 證書“更新”實際上是獲取新證書而不是更新現有證書
|
||||
|
||||
- `autocert` 配置不能熱重載
|
||||
|
||||
[🔼 返回頂部](#目錄)
|
||||
|
|
|
@ -36,7 +36,7 @@ func IsStreamHealthy(scheme, address string) bool {
|
|||
}
|
||||
|
||||
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 {
|
||||
return E.From(err)
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
var (
|
||||
NoSchemaValidation = getEnvBool("GOPROXY_NO_SCHEMA_VALIDATION")
|
||||
IsDebug = getEnvBool("GOPROXY_DEBUG")
|
||||
ProxyHTTPPort = ":" + getEnv("GOPROXY_HTTP_PORT", "80")
|
||||
ProxyHTTPSPort = ":" + getEnv("GOPROXY_HTTPS_PORT", "443")
|
||||
APIHTTPPort = ":" + getEnv("GOPROXY_API_PORT", "8888")
|
||||
ProxyHTTPAddr = getEnv("GOPROXY_HTTP_ADDR", ":80")
|
||||
ProxyHTTPSAddr = getEnv("GOPROXY_HTTPS_ADDR", ":443")
|
||||
APIHTTPAddr = getEnv("GOPROXY_API_ADDR", "127.0.0.1:8888")
|
||||
)
|
||||
|
||||
func getEnvBool(key string) bool {
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
@ -27,8 +26,6 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
||||
args := common.GetArgs()
|
||||
l := logrus.WithField("module", "main")
|
||||
|
||||
|
@ -136,15 +133,15 @@ func main() {
|
|||
proxyServer := server.InitProxyServer(server.Options{
|
||||
Name: "proxy",
|
||||
CertProvider: autocert,
|
||||
HTTPPort: common.ProxyHTTPPort,
|
||||
HTTPSPort: common.ProxyHTTPSPort,
|
||||
HTTPAddr: common.ProxyHTTPAddr,
|
||||
HTTPSAddr: common.ProxyHTTPSAddr,
|
||||
Handler: http.HandlerFunc(R.ProxyHandler),
|
||||
RedirectToHTTPS: cfg.Value().RedirectToHTTPS,
|
||||
})
|
||||
apiServer := server.InitAPIServer(server.Options{
|
||||
Name: "api",
|
||||
CertProvider: autocert,
|
||||
HTTPPort: common.APIHTTPPort,
|
||||
HTTPAddr: common.APIHTTPAddr,
|
||||
Handler: api.NewHandler(cfg),
|
||||
RedirectToHTTPS: cfg.Value().RedirectToHTTPS,
|
||||
})
|
||||
|
|
|
@ -22,11 +22,9 @@ type server struct {
|
|||
}
|
||||
|
||||
type Options struct {
|
||||
Name string
|
||||
// port (with leading colon)
|
||||
HTTPPort string
|
||||
// port (with leading colon)
|
||||
HTTPSPort string
|
||||
Name string
|
||||
HTTPAddr string
|
||||
HTTPSAddr string
|
||||
CertProvider *autocert.Provider
|
||||
RedirectToHTTPS bool
|
||||
Handler http.Handler
|
||||
|
@ -55,22 +53,22 @@ func NewServer(opt Options) (s *server) {
|
|||
certAvailable = err == nil
|
||||
}
|
||||
|
||||
if certAvailable && opt.RedirectToHTTPS && opt.HTTPSPort != "" {
|
||||
httpHandler = redirectToTLSHandler(opt.HTTPSPort)
|
||||
if certAvailable && opt.RedirectToHTTPS && opt.HTTPSAddr != "" {
|
||||
httpHandler = redirectToTLSHandler(opt.HTTPSAddr)
|
||||
} else {
|
||||
httpHandler = opt.Handler
|
||||
}
|
||||
|
||||
if opt.HTTPPort != "" {
|
||||
if opt.HTTPAddr != "" {
|
||||
httpSer = &http.Server{
|
||||
Addr: opt.HTTPPort,
|
||||
Addr: opt.HTTPAddr,
|
||||
Handler: httpHandler,
|
||||
ErrorLog: logger,
|
||||
}
|
||||
}
|
||||
if certAvailable && opt.HTTPSPort != "" {
|
||||
if certAvailable && opt.HTTPSAddr != "" {
|
||||
httpsSer = &http.Server{
|
||||
Addr: opt.HTTPSPort,
|
||||
Addr: opt.HTTPSAddr,
|
||||
Handler: opt.Handler,
|
||||
ErrorLog: logger,
|
||||
TLSConfig: &tls.Config{
|
||||
|
|
Loading…
Add table
Reference in a new issue