use logging middleware from common-lib
tronnet/workflows: Static Analysis -- Golang / static-go (push) Successful in 18s
tronnet/workflows: Static Analysis -- Golang / static-go (push) Successful in 18s
This commit is contained in:
1 parent
a13331e5a5
commit
33766d1205
2 files changed
+15
-29
No files matched your search
+14
-28
@@ -5,14 +5,10 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
paas "proxmoxaas-common-lib"
|
||||
"proxmoxaas-dashboard/app/common"
|
||||
"proxmoxaas-dashboard/app/routes"
|
||||
"proxmoxaas-dashboard/app/web"
|
||||
"time"
|
||||
|
||||
//"web" // go will complain here until the first build
|
||||
|
||||
"github.com/tdewolff/minify/v2"
|
||||
)
|
||||
|
||||
func Run() {
|
||||
@@ -24,9 +20,19 @@ func Run() {
|
||||
// setup http router
|
||||
router := http.NewServeMux()
|
||||
|
||||
// setup static resources
|
||||
m := common.InitMinify()
|
||||
ServeStatic(router, m)
|
||||
|
||||
// setup static resources under web (css, images, modules, scripts)
|
||||
static := common.MinifyStatic(m, web.Static)
|
||||
router.HandleFunc("GET /websrc/{path...}", func(w http.ResponseWriter, r *http.Request) {
|
||||
path := r.PathValue("path")
|
||||
data := static[path]
|
||||
w.Header().Set("Content-Encoding", data.MimeType.Encoding)
|
||||
w.Header().Set("Content-Type", data.MimeType.Type)
|
||||
w.Write([]byte(data.Data))
|
||||
})
|
||||
|
||||
// setup template resources
|
||||
html := common.MinifyStatic(m, web.Templates)
|
||||
common.TMPL = common.LoadHTML(html)
|
||||
|
||||
@@ -45,28 +51,8 @@ func Run() {
|
||||
router.HandleFunc("GET /login", routes.HandleGETLogin)
|
||||
router.HandleFunc("GET /settings", routes.HandleGETSettings)
|
||||
|
||||
server := LoggingMiddleware(router)
|
||||
server := paas.LoggingMiddleware(router)
|
||||
|
||||
log.Printf("[INFO] starting server listening on 0.0.0.0:%d", common.Global.Port)
|
||||
log.Fatalf("[ERR ] starting gin router: %s", http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", common.Global.Port), server))
|
||||
}
|
||||
|
||||
// setup static resources under web (css, images, modules, scripts)
|
||||
func ServeStatic(router *http.ServeMux, m *minify.M) {
|
||||
static := common.MinifyStatic(m, web.Static)
|
||||
router.HandleFunc("GET /websrc/{path...}", func(w http.ResponseWriter, r *http.Request) {
|
||||
path := r.PathValue("path")
|
||||
data := static[path]
|
||||
w.Header().Set("Content-Encoding", data.MimeType.Encoding)
|
||||
w.Header().Set("Content-Type", data.MimeType.Type)
|
||||
w.Write([]byte(data.Data))
|
||||
})
|
||||
}
|
||||
|
||||
func LoggingMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
next.ServeHTTP(w, r)
|
||||
log.Printf("%s %s %s", r.Method, r.URL.Path, time.Since(start))
|
||||
})
|
||||
}
|
||||
+1
-1
Submodule proxmoxaas-common-lib updated: 35ecaf84e0...8b73652c9b.
Reference in new issue
Block a user