mirror of
https://github.com/ncarlier/webhookd.git
synced 2025-04-09 19:53:56 +00:00
feat(): serve static assets
This commit is contained in:
parent
5dc21a0f53
commit
b0496778e8
|
@ -38,6 +38,10 @@
|
|||
# Example: `/etc/webhookd/github_deploy_key.pem`
|
||||
#WHD_SCRIPTS_GIT_KEY=
|
||||
|
||||
# Static file directory to serve on /static path, disabled by default
|
||||
# Example: `./var/www`
|
||||
#WHD_STATIC_DIR=
|
||||
|
||||
# Trust store URI, disabled by default
|
||||
# Enable HTTP signature verification if set.
|
||||
# Example: `/etc/webhookd/pubkey.pem`
|
||||
|
|
|
@ -30,6 +30,7 @@ type Routes []Route
|
|||
|
||||
var routes = Routes{
|
||||
route("/", index, middleware.Methods("GET", "POST")),
|
||||
route("/static/", static("/static/"), middleware.Methods("GET")),
|
||||
route("/healthz", healthz, middleware.Methods("GET")),
|
||||
route("/varz", varz, middleware.Methods("GET")),
|
||||
}
|
||||
|
|
19
pkg/api/static.go
Normal file
19
pkg/api/static.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/ncarlier/webhookd/pkg/config"
|
||||
)
|
||||
|
||||
func static(prefix string) HandlerFunc {
|
||||
return func(conf *config.Config) http.Handler {
|
||||
if conf.StaticDir != "" {
|
||||
fs := http.FileServer(http.Dir(conf.StaticDir))
|
||||
return http.StripPrefix(prefix, fs)
|
||||
}
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "404 page not found", http.StatusNotFound)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ type Config struct {
|
|||
ScriptDir string `flag:"scripts" desc:"Scripts location" default:"scripts"`
|
||||
PasswdFile string `flag:"passwd-file" desc:"Password file for basic HTTP authentication" default:".htpasswd"`
|
||||
LogDir string `flag:"log-dir" desc:"Hook execution logs location" default:""`
|
||||
StaticDir string `flag:"static-dir" desc:"Static file directory to serve on /static path" default:""`
|
||||
NotificationURI string `flag:"notification-uri" desc:"Notification URI"`
|
||||
TrustStoreFile string `flag:"trust-store-file" desc:"Trust store used by HTTP signature verifier (.pem or .p12)"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user