diff --git a/README.md b/README.md index 1d42e14..df7fd08 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,9 @@ "port" : 8088, "username": "admin", "password": "admin", + "directives":[ + "Set-Header Access-Control-Allow-Origin *" + ], "paths": [ { "path": "/", @@ -55,10 +58,12 @@ { "path": "/ws", "upstreams":["http://localhost:3000"], - "pathrewrite": { - "replace": "/ws", - "with": "/" - } + "directives":[ + "HostSchemas $target", + "HeaderOrigin", + "Path /ws /", + "RemoveCookie token" + ] } ] }] @@ -77,6 +82,8 @@ servers 配置 - paths 路径配置 - certfile 证书文件 - keyfile 证书密钥文件 +- directives 指令 针对response的指令,目前只实现了set-header + paths 配置 @@ -84,9 +91,23 @@ paths 配置 - root 根目录 - default 默认文件 - upstreams 代理地址 -- pathrewrite 路径重写 +- directives 这里指令针对的是代理请求,有以下几种: + - HostSchemas [$target] 代理地址 + - HeaderOrigin 代理请求时,添加Origin头 + - Path [/ws] [/] 代理请求时,重写URL路径,用第二个参数替换url中的第一个部分 + - RemoveCookie [token] 代理请求时,删除cookie中的某些字段 +### 指令系统 +指令系统采用了nginx的指令系统,指令的格式为: + +``` +指令名 参数1 参数2 ... 参数n +``` +指令系统用来对特定的request/response进行处理。目前只支持: + +- 返回的response中设置header +- 反向代理时,修改发送到上游服务器的请求 ## Packages diff --git a/hander/proxyupdater.go b/hander/proxyupdater.go index 6a0ef47..47cd13f 100644 --- a/hander/proxyupdater.go +++ b/hander/proxyupdater.go @@ -30,7 +30,7 @@ var ProxyRequestUpdateMap = map[string]ProxyRequestUpdater{ with := arg[1] return func(r *http.Request) { r.URL.Path = r.URL.Path[len(replace):] - r.URL.Path = with + r.URL.Path + r.URL.Path = strings.TrimSuffix(with, "/") + r.URL.Path } }, "RemoveCookie": func(arg ...string) func(r *http.Request) { diff --git a/target/adminui/index.html b/target/adminui/index.html new file mode 100644 index 0000000..30bd6d0 --- /dev/null +++ b/target/adminui/index.html @@ -0,0 +1,5 @@ + +
+