From d980980a0b85646fae23d6fbac2657749abe9bad Mon Sep 17 00:00:00 2001 From: James Mills <1290234+prologic@users.noreply.github.com> Date: Sun, 12 Mar 2023 14:24:34 +1000 Subject: [PATCH] Add support for specifying root driectory for zs serve --- Dockerfile | 4 +++- main.go | 14 +++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index c78862d..cc350a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,6 +47,8 @@ RUN addgroup -g "${PGID}" zs && \ adduser -D -H -G zs -h /var/empty -u "${PUID}" zs && \ mkdir -p /data && chown -R zs:zs /data +EXPOSE 8000/tcp + VOLUME /data WORKDIR / @@ -57,4 +59,4 @@ COPY .dockerfiles/entrypoint.sh /init ENTRYPOINT ["/init"] -CMD ["zs""] +CMD ["zs"", "serve", "0.0.0.0:8000", "/data"] diff --git a/main.go b/main.go index a281d39..9427bcb 100644 --- a/main.go +++ b/main.go @@ -329,13 +329,13 @@ func buildAll(ctx context.Context, watch bool) { } // serve runs a static web server and builds and continuously watches for changes to rebuild -func serve(ctx context.Context, bind string) error { - os.Mkdir(PUBDIR, 0755) +func serve(ctx context.Context, bind, root string) error { + os.Mkdir(root, 0755) svr, err := static.NewServer( static.WithBind(bind), static.WithDir(true), - static.WithRoot(PUBDIR), + static.WithRoot(root), static.WithSPA(true), ) if err != nil { @@ -386,10 +386,14 @@ func main() { buildAll(ctx, true) case "serve": bind := ":8000" - if len(args) > 1 { + root := PUBDIR + if len(args) > 0 { bind = args[0] } - if err := serve(ctx, bind); err != nil { + if len(args) > 1 { + root = args[1] + } + if err := serve(ctx, bind, root); err != nil { fmt.Println("ERROR: " + err.Error()) } case "var":