修复 event 案例错误,为 redirect 添加重定向配置

This commit is contained in:
dragon
2025-11-21 13:54:48 +08:00
parent 858ea9f9cf
commit 277f7e4226
2 changed files with 18 additions and 6 deletions

View File

@@ -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
}