update readme

This commit is contained in:
kingecg 2023-12-15 22:40:12 +08:00
parent f86fa0112e
commit 8204c37dc3
5 changed files with 90 additions and 6 deletions

View File

@ -35,6 +35,9 @@
"port" : 8088, "port" : 8088,
"username": "admin", "username": "admin",
"password": "admin", "password": "admin",
"directives":[
"Set-Header Access-Control-Allow-Origin *"
],
"paths": [ "paths": [
{ {
"path": "/", "path": "/",
@ -55,10 +58,12 @@
{ {
"path": "/ws", "path": "/ws",
"upstreams":["http://localhost:3000"], "upstreams":["http://localhost:3000"],
"pathrewrite": { "directives":[
"replace": "/ws", "HostSchemas $target",
"with": "/" "HeaderOrigin",
} "Path /ws /",
"RemoveCookie token"
]
} }
] ]
}] }]
@ -77,6 +82,8 @@ servers 配置
- paths 路径配置 - paths 路径配置
- certfile 证书文件 - certfile 证书文件
- keyfile 证书密钥文件 - keyfile 证书密钥文件
- directives 指令 针对response的指令目前只实现了set-header
paths 配置 paths 配置
@ -84,9 +91,23 @@ paths 配置
- root 根目录 - root 根目录
- default 默认文件 - default 默认文件
- upstreams 代理地址 - upstreams 代理地址
- pathrewrite 路径重写 - directives 这里指令针对的是代理请求,有以下几种:
- HostSchemas [$target] 代理地址
- HeaderOrigin 代理请求时添加Origin头
- Path [/ws] [/] 代理请求时重写URL路径用第二个参数替换url中的第一个部分
- RemoveCookie [token] 代理请求时删除cookie中的某些字段
### 指令系统
指令系统采用了nginx的指令系统指令的格式为
```
指令名 参数1 参数2 ... 参数n
```
指令系统用来对特定的request/response进行处理。目前只支持
- 返回的response中设置header
- 反向代理时,修改发送到上游服务器的请求
## Packages ## Packages

View File

@ -30,7 +30,7 @@ var ProxyRequestUpdateMap = map[string]ProxyRequestUpdater{
with := arg[1] with := arg[1]
return func(r *http.Request) { return func(r *http.Request) {
r.URL.Path = r.URL.Path[len(replace):] 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) { "RemoveCookie": func(arg ...string) func(r *http.Request) {

View File

@ -0,0 +1,5 @@
<html>
<body>
<h1>GoHttpd Running...</h1>
</body>
</html>

58
target/config.json Normal file
View File

@ -0,0 +1,58 @@
{
"logging" :{
"appenders": {
"out" :{
"type": "file",
"options":{
"file": "gohttpd.log"
}
},
"stdout":{
"type": "console"
}
},
"categories": {
"default": {
"appenders": [ "out" ,"stdout"],
"level": "debug"
}
}
},
"admin" : {
"name": "admin",
"port" : 8088,
"username": "admin",
"password": "admin",
"directives":[
"Set-Header Access-Control-Allow-Origin *",
"Set-Header Access-Control-Allow-Methods GET, POST, PUT, DELETE, OPTIONS",
"Set-Header Access-Control-Allow-Headers Content-Type, Authorization, Content-Length, X-Requested-With"
],
"paths": [
{
"path": "/",
"root": "./adminui",
"default": "index.html"
}
]
},
"servers":[{
"port" : 8080,
"name":"demo",
"paths":[
{
"path": "/",
"root": "./public/",
"default": "index.html"
},
{
"path": "/ws",
"upstreams":["http://localhost:3000"],
"pathrewrite": {
"replace": "/ws",
"with": "/"
}
}
]
}]
}

BIN
target/gohttpd Executable file

Binary file not shown.