2024-01-07 11:58:06 +01:00
|
|
|
package webservice
|
|
|
|
|
|
|
|
import (
|
|
|
|
// Standard
|
|
|
|
"embed"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2024-01-07 16:18:49 +01:00
|
|
|
"regexp"
|
2024-01-07 11:58:06 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
//go:embed static/js
|
|
|
|
embedded embed.FS
|
2024-01-07 16:18:49 +01:00
|
|
|
pathMatcher *regexp.Regexp = regexp.MustCompile("^/_js/v[0-9]+/(.*)$")
|
2024-01-07 11:58:06 +01:00
|
|
|
)
|
|
|
|
|
2024-01-07 16:18:49 +01:00
|
|
|
func (service *Service) staticJSHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var path string
|
|
|
|
if comp := pathMatcher.FindStringSubmatch(r.URL.Path); comp != nil {
|
|
|
|
path = fmt.Sprintf("static/js/%s", comp[1])
|
|
|
|
} else {
|
|
|
|
service.logger.Debug("webservice", "request", r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
service.logger.Debug("webservice", "request", r.URL.Path, "path", path)
|
|
|
|
w.Header().Add("Content-Type", "text/javascript")
|
|
|
|
|
|
|
|
contents, err := embedded.ReadFile(path)
|
2024-01-07 11:58:06 +01:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
w.Write(contents)
|
|
|
|
}
|