Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
feat: add redirect on missing reference
Browse files Browse the repository at this point in the history
Calling /branch/, /branch, /tag, /tag/ will redirect to /
  • Loading branch information
saitho committed Dec 28, 2020
1 parent bac16cf commit 717926b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,15 @@ func main() {

server.AddHandler(`^/webhook/github`, webserver.GitHubWebHookEndpoint(cfg, client))
if cfg.Display.Tags.VirtualTags.EnableSemverMajor {
server.AddHandler(`^/tag/(v?\d+)/-/(.*)`, resolveVirtualMajorTag)
server.AddHandler(`^/tag/(v?\d+)/-/(.*)$`, resolveVirtualMajorTag)
server.AddHandler(`^/tag/(v?\d+)/?$`, resolveVirtualMajorTag)
}

server.AddHandler(`^/(branch|tag)/(.*)/-/(.*)`, handler)
server.AddHandler(`^/(branch|tag)/(.*)/-/(.*)$`, handler)
server.AddHandler(`^/(branch|tag)/(.*)/?$`, handler)
server.AddHandler(`^/(branch|tag)/?$`, func(resp *webserver.Response, req *webserver.Request) {
http.Redirect(resp, req.Request, "/", http.StatusPermanentRedirect)
})
server.AddHandler(`^/$`, func(resp *webserver.Response, req *webserver.Request) {
if err := initRepo(); err != nil {
resp.Text(http.StatusInternalServerError, err.Error())
Expand Down
3 changes: 2 additions & 1 deletion webserver/request_handler.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package webserver

import (
"github.com/saitho/static-git-file-server/config"
"io"
"net/http"
"regexp"

"github.com/gabriel-vasile/mimetype"

"github.com/saitho/static-git-file-server/config"
)

type Handler func(*Response, *Request)
Expand Down

0 comments on commit 717926b

Please sign in to comment.