Commit 4e86452f authored by ale's avatar ale
Browse files

Set template and static directories from command-line

The defaults align with the Debian package contents.
parent 8b8087b0
Pipeline #415 passed with stages
in 1 minute and 18 seconds
......@@ -10,6 +10,7 @@ import (
htemplate "html/template"
"io/ioutil"
"net/http"
"path/filepath"
"strings"
ttemplate "text/template"
......@@ -64,6 +65,8 @@ type serverCommand struct {
senderAddr string
senderName string
ratelimitConfigFile string
templateDir string
staticDir string
}
func newServerCommand() *serverCommand { return &serverCommand{} }
......@@ -101,6 +104,8 @@ func (c *serverCommand) SetFlags(f *flag.FlagSet) {
f.StringVar(&c.senderAddr, "sender-addr", "idp@localhost", "email sender address")
f.StringVar(&c.senderName, "sender-name", "IDP", "email sender name")
f.StringVar(&c.ratelimitConfigFile, "ratelimit-config", "", "configuration for rate limiters / blacklists")
f.StringVar(&c.templateDir, "template-dir", "/usr/share/idp/templates", "location of templates")
f.StringVar(&c.staticDir, "static-dir", "/usr/share/idp/static", "location of static content")
setFlagDefaultsFromEnv(f)
}
......@@ -180,8 +185,8 @@ func (c *serverCommand) run(ctx context.Context) error {
return fmt.Errorf("Connection to Hydra failed: %v", err)
}
htmlTpl := htemplate.Must(htemplate.ParseGlob("./templates/*.html"))
emailTpl := ttemplate.Must(ttemplate.ParseGlob("./templates/email/*.txt"))
htmlTpl := htemplate.Must(htemplate.ParseGlob(filepath.Join(c.templateDir, "*.html")))
emailTpl := ttemplate.Must(ttemplate.ParseGlob(filepath.Join(c.templateDir, "email", "*.txt")))
var rlConfig []byte
if c.ratelimitConfigFile != "" {
......@@ -216,7 +221,7 @@ func (c *serverCommand) run(ctx context.Context) error {
func (c *serverCommand) runServer(app *idpapp.App) error {
csrfWrapper := csrf.Protect(securecookie.GenerateRandomKey(32), csrf.Secure(false))
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(c.staticDir))))
http.Handle("/metrics", promhttp.Handler())
http.Handle("/", csrfWrapper(app.HTTPHandler()))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment