mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-20 06:08:21 +00:00
parent
9b3929b7fa
commit
540ad108df
1 changed files with 18 additions and 4 deletions
|
@ -18,7 +18,9 @@ import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -35,6 +37,15 @@ var (
|
||||||
indexHTML []byte
|
indexHTML []byte
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type prefixFS struct {
|
||||||
|
fs http.FileSystem
|
||||||
|
prefix string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *prefixFS) Open(name string) (http.File, error) {
|
||||||
|
return f.fs.Open(strings.TrimPrefix(name, f.prefix))
|
||||||
|
}
|
||||||
|
|
||||||
// New returns a gin engine to serve the web frontend.
|
// New returns a gin engine to serve the web frontend.
|
||||||
func New() (*gin.Engine, error) {
|
func New() (*gin.Engine, error) {
|
||||||
e := gin.New()
|
e := gin.New()
|
||||||
|
@ -42,14 +53,17 @@ func New() (*gin.Engine, error) {
|
||||||
|
|
||||||
e.Use(setupCache)
|
e.Use(setupCache)
|
||||||
|
|
||||||
|
rootURL, _ := url.Parse(server.Config.Server.RootURL)
|
||||||
|
rootPath := rootURL.Path
|
||||||
|
|
||||||
httpFS, err := web.HTTPFS()
|
httpFS, err := web.HTTPFS()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
h := http.FileServer(httpFS)
|
h := http.FileServer(&prefixFS{httpFS, rootPath})
|
||||||
e.GET("/favicon.svg", redirect("/favicons/favicon-light-default.svg", http.StatusPermanentRedirect))
|
e.GET(rootPath+"/favicon.svg", redirect(server.Config.Server.RootURL+"/favicons/favicon-light-default.svg", http.StatusPermanentRedirect))
|
||||||
e.GET("/favicons/*filepath", gin.WrapH(h))
|
e.GET(rootPath+"/favicons/*filepath", gin.WrapH(h))
|
||||||
e.GET("/assets/*filepath", gin.WrapH(h))
|
e.GET(rootPath+"/assets/*filepath", gin.WrapH(h))
|
||||||
|
|
||||||
e.NoRoute(handleIndex)
|
e.NoRoute(handleIndex)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue