修复自定义域名的问题

This commit is contained in:
ExplodingDragon
2025-04-15 20:45:45 +08:00
parent 1fd4dc4ef0
commit 036569ac5f
4 changed files with 13 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
package pkg
import (
"fmt"
"io"
"mime"
"net/http"
@@ -98,6 +99,11 @@ func (s *Server) Serve(writer http.ResponseWriter, request *http.Request) error
}
zap.L().Debug("获取请求", zap.Any("request", meta.Path))
// todo(feat) : 支持 http range
if meta.Domain != "" && meta.Domain != request.Host {
zap.L().Debug("重定向地址", zap.Any("src", request.Host), zap.Any("dst", meta.Domain))
http.Redirect(writer, request, fmt.Sprintf("https://%s/%s", meta.Domain, meta.Path), http.StatusFound)
return nil
}
result, err := s.reader.Open(meta.Owner, meta.Repo, meta.CommitID, meta.Path)
if err != nil {
if meta.HistoryRouteMode && errors.Is(err, os.ErrNotExist) {