Changes
9 changed files (+48/-16)
-
-
@@ -28,8 +28,12 @@ dirs:# <https://pkg.go.dev/html/template> templates: ./templates # Path to a directory containing static assets. # User can access files in this directory by accessing "/static/*". # [optional] # Path to a directory containing custom static assets. # If you omit this, legit will use its default static asset directory # ("static" directory next to this file) embedded in the binary. # # Visitors can access files in this directory by accessing "/static/*". static: ./static meta:
-
-
-
@@ -58,8 +58,12 @@ func Read(f string) (*Config, error) {if c.Dirs.Templates, err = resolvePath(c.Dirs.Templates, f); err != nil { return nil, err } if c.Dirs.Static, err = resolvePath(c.Dirs.Static, f); err != nil { return nil, err // Override static dir if c.Dirs.Static != "" { if c.Dirs.Static, err = resolvePath(c.Dirs.Static, f); err != nil { return nil, err } } return &c, nil
-
-
-
@@ -30,7 +30,6 @@ repo:dirs: templates: ../templates static: ../static meta: title: legit Demo
-
-
-
@@ -31,7 +31,6 @@root = ./.; fileset = pkgs.lib.fileset.unions [ ./config.yaml ./static ./templates ]; };
-
@@ -47,6 +46,7 @@fileset = unions [ ./go.mod ./go.sum ./static (fileFilter (file: file.hasExt "go") ./.) ]; };
-
-
-
@@ -1,16 +1,22 @@package main import ( "embed" "flag" "fmt" "io/fs" "log" "math" "net/http" "os" "github.com/pocka/legit/config" "github.com/pocka/legit/routes" ) //go:embed static/* var defaultStaticDir embed.FS func main() { var cfg string var host string
-
@@ -46,7 +52,23 @@ func main() {log.Fatalf("unveil: %s", err) } mux := routes.Handlers(c) var staticDir fs.FS if c.Dirs.Static != "" { root, err := os.OpenRoot(c.Dirs.Static) if err != nil { log.Fatalf("Unable to open static dir: %s", err) } defer root.Close() staticDir = root.FS() } else { staticDir, err = fs.Sub(defaultStaticDir, "static") if err != nil { log.Fatalf("Unable to open default static dir: %s", err) } } mux := routes.Handlers(c, staticDir) addr := fmt.Sprintf("%s:%d", c.Server.Host, c.Server.Port) log.Println("starting server on", addr) log.Fatal(http.ListenAndServe(addr, mux))
-
-
-
@@ -1,6 +1,7 @@package routes import ( "io/fs" "net/http" "github.com/microcosm-cc/bluemonday"
-
@@ -29,10 +30,11 @@ func (d *deps) Multiplex(w http.ResponseWriter, r *http.Request) {} } func Handlers(c *config.Config) *http.ServeMux { func Handlers(c *config.Config, staticDir fs.FS) *http.ServeMux { mux := http.NewServeMux() d := deps{ c: c, staticDir: staticDir, ugcPolicy: bluemonday.UGCPolicy(), }
-
-
-
@@ -5,6 +5,7 @@ import ("compress/gzip" "fmt" "html/template" "io/fs" "log" "net/http" "net/url"
-
@@ -25,6 +26,10 @@ import (type deps struct { c *config.Config // staticDir should be path traversal attack resilient FS, such as the one // returned by "os.Root.FS". staticDir fs.FS // ugcPolicy is a bluemonday policy for user generated content. ugcPolicy *bluemonday.Policy }
-
@@ -636,13 +641,12 @@ func (d *deps) Refs(w http.ResponseWriter, r *http.Request) {} func (d *deps) ServeStatic(w http.ResponseWriter, r *http.Request) { f := r.PathValue("file") f = filepath.Clean(f) f, err := securejoin.SecureJoin(d.c.Dirs.Static, f) if err != nil { name := r.PathValue("file") name = filepath.Clean(name) if !filepath.IsLocal(name) { d.Write404(w) return } http.ServeFile(w, r, f) http.ServeFileFS(w, r, d.staticDir, name) }
-
-
-
@@ -10,7 +10,6 @@ repo:dirs: templates: ../../templates static: ../../static meta: title: Legit Load Testing
-
-
-
@@ -15,7 +15,6 @@ stdenv.mkDerivation {fileset = lib.fileset.unions [ ./create_repos.bash ./config.yaml ../../static ../../templates ]; };
-
@@ -25,7 +24,6 @@ stdenv.mkDerivation {cd $out/tests/k6/repos bash $src/tests/k6/create_repos.bash ln -s $src/tests/k6/config.yaml $out/tests/k6/config.yaml ln -s $src/static $out/static ln -s $src/templates $out/templates '';
-