From d083d5d72e4bf496b8152d14986818a5b63fe301 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Sat, 17 Dec 2022 12:45:21 +0530 Subject: routes: serve static content from /static --- routes/routes.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'routes/routes.go') diff --git a/routes/routes.go b/routes/routes.go index aab28f5..5a8d686 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -42,6 +42,7 @@ func (d *deps) Index(w http.ResponseWriter, r *http.Request) { if err != nil { d.Write500(w) log.Println(err) + return } var desc string @@ -59,7 +60,7 @@ func (d *deps) Index(w http.ResponseWriter, r *http.Request) { }) } - tpath := filepath.Join(d.c.Template.Dir, "*") + tpath := filepath.Join(d.c.Dirs.Templates, "*") t := template.Must(template.ParseGlob(tpath)) data := make(map[string]interface{}) @@ -186,7 +187,7 @@ func (d *deps) Log(w http.ResponseWriter, r *http.Request) { return } - tpath := filepath.Join(d.c.Template.Dir, "*") + tpath := filepath.Join(d.c.Dirs.Templates, "*") t := template.Must(template.ParseGlob(tpath)) data := make(map[string]interface{}) @@ -219,7 +220,7 @@ func (d *deps) Diff(w http.ResponseWriter, r *http.Request) { return } - tpath := filepath.Join(d.c.Template.Dir, "*") + tpath := filepath.Join(d.c.Dirs.Templates, "*") t := template.Must(template.ParseGlob(tpath)) data := make(map[string]interface{}) @@ -260,7 +261,7 @@ func (d *deps) Refs(w http.ResponseWriter, r *http.Request) { return } - tpath := filepath.Join(d.c.Template.Dir, "*") + tpath := filepath.Join(d.c.Dirs.Templates, "*") t := template.Must(template.ParseGlob(tpath)) data := make(map[string]interface{}) @@ -275,3 +276,10 @@ func (d *deps) Refs(w http.ResponseWriter, r *http.Request) { return } } + +func (d *deps) ServeStatic(w http.ResponseWriter, r *http.Request) { + f := flow.Param(r.Context(), "file") + f = filepath.Clean(filepath.Join(d.c.Dirs.Static, f)) + + http.ServeFile(w, r, f) +} -- cgit