mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 01:57:02 +00:00
config: Combine TemplateDir and PublicDir into UIDir
- Define static names for `templates` and `static`
This commit is contained in:
@@ -57,10 +57,9 @@ type POP3 struct {
|
|||||||
// Web contains the HTTP server configuration.
|
// Web contains the HTTP server configuration.
|
||||||
type Web struct {
|
type Web struct {
|
||||||
Addr string `required:"true" default:"0.0.0.0:9000" desc:"Web server IP4 host:port"`
|
Addr string `required:"true" default:"0.0.0.0:9000" desc:"Web server IP4 host:port"`
|
||||||
TemplateDir string `required:"true" default:"ui/templates" desc:"Theme template dir"`
|
UIDir string `required:"true" default:"ui" desc:"User interface dir"`
|
||||||
TemplateCache bool `required:"true" default:"true" desc:"Cache templates after first use?"`
|
|
||||||
PublicDir string `required:"true" default:"ui/static" desc:"Theme public dir"`
|
|
||||||
GreetingFile string `required:"true" default:"ui/greeting.html" desc:"Home page greeting HTML"`
|
GreetingFile string `required:"true" default:"ui/greeting.html" desc:"Home page greeting HTML"`
|
||||||
|
TemplateCache bool `required:"true" default:"true" desc:"Cache templates after first use?"`
|
||||||
MailboxPrompt string `required:"true" default:"@inbucket" desc:"Prompt next to mailbox input"`
|
MailboxPrompt string `required:"true" default:"@inbucket" desc:"Prompt next to mailbox input"`
|
||||||
CookieAuthKey string `desc:"Session cipher key (text)"`
|
CookieAuthKey string `desc:"Session cipher key (text)"`
|
||||||
MonitorVisible bool `required:"true" default:"true" desc:"Show monitor tab in UI?"`
|
MonitorVisible bool `required:"true" default:"true" desc:"Show monitor tab in UI?"`
|
||||||
|
|||||||
@@ -36,8 +36,7 @@ func setupWebServer(mm message.Manager) *bytes.Buffer {
|
|||||||
http.DefaultServeMux = http.NewServeMux()
|
http.DefaultServeMux = http.NewServeMux()
|
||||||
cfg := &config.Root{
|
cfg := &config.Root{
|
||||||
Web: config.Web{
|
Web: config.Web{
|
||||||
TemplateDir: "../themes/bootstrap/templates",
|
UIDir: "../ui",
|
||||||
PublicDir: "../themes/bootstrap/public",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
shutdownChan := make(chan bool)
|
shutdownChan := make(chan bool)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"expvar"
|
"expvar"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
@@ -20,6 +21,11 @@ import (
|
|||||||
// Handler is a function type that handles an HTTP request in Inbucket
|
// Handler is a function type that handles an HTTP request in Inbucket
|
||||||
type Handler func(http.ResponseWriter, *http.Request, *Context) error
|
type Handler func(http.ResponseWriter, *http.Request, *Context) error
|
||||||
|
|
||||||
|
const (
|
||||||
|
staticDir = "static"
|
||||||
|
templateDir = "templates"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// msgHub holds a reference to the message pub/sub system
|
// msgHub holds a reference to the message pub/sub system
|
||||||
msgHub *msghub.Hub
|
msgHub *msghub.Hub
|
||||||
@@ -59,10 +65,10 @@ func Initialize(
|
|||||||
manager = mm
|
manager = mm
|
||||||
|
|
||||||
// Content Paths
|
// Content Paths
|
||||||
log.Infof("HTTP templates mapped to %q", conf.Web.TemplateDir)
|
staticPath := filepath.Join(conf.Web.UIDir, staticDir)
|
||||||
log.Infof("HTTP static content mapped to %q", conf.Web.PublicDir)
|
log.Infof("Web UI content mapped to path: %s", conf.Web.UIDir)
|
||||||
Router.PathPrefix("/public/").Handler(http.StripPrefix("/public/",
|
Router.PathPrefix("/public/").Handler(http.StripPrefix("/public/",
|
||||||
http.FileServer(http.Dir(conf.Web.PublicDir))))
|
http.FileServer(http.Dir(staticPath))))
|
||||||
http.Handle("/", Router)
|
http.Handle("/", Router)
|
||||||
|
|
||||||
// Session cookie setup
|
// Session cookie setup
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/jhillyerd/inbucket/pkg/log"
|
"github.com/jhillyerd/inbucket/pkg/log"
|
||||||
@@ -49,8 +48,7 @@ func ParseTemplate(name string, partial bool) (*template.Template, error) {
|
|||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
tempPath := strings.Replace(name, "/", string(filepath.Separator), -1)
|
tempFile := filepath.Join(rootConfig.Web.UIDir, templateDir, filepath.FromSlash(name))
|
||||||
tempFile := filepath.Join(rootConfig.Web.TemplateDir, tempPath)
|
|
||||||
log.Tracef("Parsing template %v", tempFile)
|
log.Tracef("Parsing template %v", tempFile)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
@@ -62,7 +60,8 @@ func ParseTemplate(name string, partial bool) (*template.Template, error) {
|
|||||||
t, err = t.ParseFiles(tempFile)
|
t, err = t.ParseFiles(tempFile)
|
||||||
} else {
|
} else {
|
||||||
t = template.New("_base.html").Funcs(TemplateFuncs)
|
t = template.New("_base.html").Funcs(TemplateFuncs)
|
||||||
t, err = t.ParseFiles(filepath.Join(rootConfig.Web.TemplateDir, "_base.html"), tempFile)
|
t, err = t.ParseFiles(
|
||||||
|
filepath.Join(rootConfig.Web.UIDir, templateDir, "_base.html"), tempFile)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user