修复 event 案例错误,为 redirect 添加重定向配置
This commit is contained in:
@@ -12,11 +12,15 @@ async function eventPull() {
|
||||
await ws.writeText(data);
|
||||
}
|
||||
}
|
||||
|
||||
async function messagePull() {
|
||||
while (true) {
|
||||
const data = await ws.readText()
|
||||
if (data === "exit") break;
|
||||
if (data === "exit")
|
||||
await event.put("messages", JSON.stringify({
|
||||
name:name,
|
||||
data: name+' 已断开连接'
|
||||
}));
|
||||
break;
|
||||
if (data?.trim()) {
|
||||
await event.put("messages", JSON.stringify({
|
||||
name:name,
|
||||
@@ -27,5 +31,5 @@ async function messagePull() {
|
||||
}
|
||||
|
||||
(async () => {
|
||||
await Promise.all([eventPull(), messagePull()])
|
||||
await Promise.any([eventPull(), messagePull()])
|
||||
})()
|
||||
@@ -15,7 +15,16 @@ import (
|
||||
|
||||
var portExp = regexp.MustCompile(`:\d+$`)
|
||||
|
||||
func FilterInstRedirect(_ core.Params) (core.FilterInstance, error) {
|
||||
func FilterInstRedirect(g core.Params) (core.FilterInstance, error) {
|
||||
var global struct {
|
||||
Scheme string `json:"scheme"`
|
||||
}
|
||||
if err := g.Unmarshal(&global); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if global.Scheme == "" {
|
||||
global.Scheme = "https"
|
||||
}
|
||||
return func(config core.Params) (core.FilterCall, error) {
|
||||
var param struct {
|
||||
Targets []string `json:"targets"`
|
||||
@@ -42,12 +51,11 @@ func FilterInstRedirect(_ core.Params) (core.FilterInstance, error) {
|
||||
if strings.HasSuffix(path, "/index.html") || path == "index.html" {
|
||||
path = strings.TrimSuffix(path, "index.html")
|
||||
}
|
||||
target, err := url.Parse(fmt.Sprintf("https://%s/%s", param.Targets[0], path))
|
||||
target, err := url.Parse(fmt.Sprintf("%s://%s/%s", global.Scheme, param.Targets[0], path))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
target.RawQuery = request.URL.RawQuery
|
||||
|
||||
http.Redirect(writer, request, target.String(), param.Code)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user