🐛 Fixed router paths for static
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Maxim Lebedev 2023-03-16 23:46:17 +06:00
parent c1534501b3
commit b1a2b5f56f
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
1 changed files with 15 additions and 15 deletions

30
main.go
View File

@ -108,7 +108,7 @@ var (
var cpuProfilePath, memProfilePath string var cpuProfilePath, memProfilePath string
//go:embed web/static/* //go:embed web/static/*
var staticFS embed.FS var static embed.FS
//nolint:gochecknoinits //nolint:gochecknoinits
func init() { func init() {
@ -155,7 +155,7 @@ func main() {
var opts NewAppOptions var opts NewAppOptions
var err error var err error
if opts.Static, err = fs.Sub(staticFS, filepath.Join("web", "static")); err != nil { if opts.Static, err = fs.Sub(static, filepath.Join("web", "static")); err != nil {
logger.Fatalln(err) logger.Fatalln(err)
} }
@ -342,41 +342,41 @@ func (app *App) Handler() http.Handler {
}).Handler() }).Handler()
user := userhttpdelivery.NewHandler(app.tokens, config).Handler() user := userhttpdelivery.NewHandler(app.tokens, config).Handler()
ticket := tickethttpdelivery.NewHandler(app.tickets, app.matcher, *config).Handler() ticket := tickethttpdelivery.NewHandler(app.tickets, app.matcher, *config).Handler()
static := http.FileServer(http.FS(app.static)) staticHandler := http.FileServer(http.FS(app.static))
return http.HandlerFunc(middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var head string head, tail := urlutil.ShiftPath(r.URL.Path)
head, r.URL.Path = urlutil.ShiftPath(r.URL.Path)
switch head {
case "", "callback", "token", "introspect", "revocation":
if r.URL.Path != "/" {
r.URL = r.URL.JoinPath(head, r.URL.Path)
} else {
r.URL = r.URL.JoinPath(head)
}
}
switch head { switch head {
default: default:
static.ServeHTTP(w, r) staticHandler.ServeHTTP(w, r)
case "", "callback": case "", "callback":
client.ServeHTTP(w, r) client.ServeHTTP(w, r)
case "token", "introspect", "revocation": case "token", "introspect", "revocation":
token.ServeHTTP(w, r) token.ServeHTTP(w, r)
case ".well-known": case ".well-known":
r.URL.Path = tail
if head, _ = urlutil.ShiftPath(r.URL.Path); head == "oauth-authorization-server" { if head, _ = urlutil.ShiftPath(r.URL.Path); head == "oauth-authorization-server" {
metadata.ServeHTTP(w, r) metadata.ServeHTTP(w, r)
} else { } else {
http.NotFound(w, r) http.NotFound(w, r)
} }
case "authorize": case "authorize":
r.URL.Path = tail
auth.ServeHTTP(w, r) auth.ServeHTTP(w, r)
case "health": case "health":
r.URL.Path = tail
health.ServeHTTP(w, r) health.ServeHTTP(w, r)
case "userinfo": case "userinfo":
r.URL.Path = tail
user.ServeHTTP(w, r) user.ServeHTTP(w, r)
case "ticket": case "ticket":
r.URL.Path = tail
ticket.ServeHTTP(w, r) ticket.ServeHTTP(w, r)
} }
}).Intercept(middleware.LogFmt())) }).Intercept(middleware.LogFmt()))