mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 07:40:56 +08:00 
			
		
		
		
	自定义页面增加“跳转URL”功能
This commit is contained in:
		@@ -2,7 +2,6 @@ package nodes
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/utils"
 | 
			
		||||
	"github.com/iwind/TeaGo/Tea"
 | 
			
		||||
@@ -48,7 +47,7 @@ func (this *HTTPRequest) doPage(status int) (shouldStop bool) {
 | 
			
		||||
func (this *HTTPRequest) doPageLookup(pages []*serverconfigs.HTTPPageConfig, status int) (shouldStop bool) {
 | 
			
		||||
	for _, page := range pages {
 | 
			
		||||
		if page.Match(status) {
 | 
			
		||||
			if len(page.BodyType) == 0 || page.BodyType == shared.BodyTypeURL {
 | 
			
		||||
			if len(page.BodyType) == 0 || page.BodyType == serverconfigs.HTTPPageBodyTypeURL {
 | 
			
		||||
				if urlSchemeRegexp.MatchString(page.URL) {
 | 
			
		||||
					var newStatus = page.NewStatus
 | 
			
		||||
					if newStatus <= 0 {
 | 
			
		||||
@@ -115,7 +114,7 @@ func (this *HTTPRequest) doPageLookup(pages []*serverconfigs.HTTPPageConfig, sta
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				return true
 | 
			
		||||
			} else if page.BodyType == shared.BodyTypeHTML {
 | 
			
		||||
			} else if page.BodyType == serverconfigs.HTTPPageBodyTypeHTML {
 | 
			
		||||
				// 这里需要实现设置Status,因为在Format()中可以获取${status}等变量
 | 
			
		||||
				if page.NewStatus > 0 {
 | 
			
		||||
					this.writer.statusCode = page.NewStatus
 | 
			
		||||
@@ -147,6 +146,18 @@ func (this *HTTPRequest) doPageLookup(pages []*serverconfigs.HTTPPageConfig, sta
 | 
			
		||||
					this.writer.SetOk()
 | 
			
		||||
				}
 | 
			
		||||
				return true
 | 
			
		||||
			} else if page.BodyType == serverconfigs.HTTPPageBodyTypeRedirectURL {
 | 
			
		||||
				var newURL = page.URL
 | 
			
		||||
				if len(newURL) == 0 {
 | 
			
		||||
					newURL = "/"
 | 
			
		||||
				}
 | 
			
		||||
				if page.NewStatus > 0 && httpStatusIsRedirect(page.NewStatus) {
 | 
			
		||||
					httpRedirect(this.writer, this.RawReq, newURL, page.NewStatus)
 | 
			
		||||
				} else {
 | 
			
		||||
					httpRedirect(this.writer, this.RawReq, newURL, http.StatusTemporaryRedirect)
 | 
			
		||||
				}
 | 
			
		||||
				this.writer.SetOk()
 | 
			
		||||
				return true
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user