浏览代码

Prioritise --static-dir on init when no assets are embedded.

When no static assets are found on init, i.e., when a binary without
stuffbin assets are loaded, the app looks for all necessary static
files in the working dir, including the `./static/*` path which renders
the `--static-dir` flag irrelevant.

This patch gives `--static-dir`, if set, precedence over `./static/*`
when loading assets from the working dir when a binary is not stuffed
with static files.

Closes #340.
Kailash Nadh 4 年之前
父节点
当前提交
d695bb34cc
共有 1 个文件被更改,包括 5 次插入4 次删除
  1. 5 4
      cmd/init.go

+ 5 - 4
cmd/init.go

@@ -126,10 +126,6 @@ func initFS(staticDir, i18nDir string) stuffbin.FileSystem {
 			"config.toml.sample",
 			"queries.sql",
 			"schema.sql",
-			"static/email-templates",
-
-			// Alias /static/public to /public for the HTTP fileserver.
-			"static/public:/public",
 
 			// The frontend app's static assets are aliased to /frontend
 			// so that they are accessible at /frontend/js/* etc.
@@ -139,6 +135,11 @@ func initFS(staticDir, i18nDir string) stuffbin.FileSystem {
 			"i18n:/i18n",
 		}
 
+		// If no external static dir is provided, try to load from the working dir.
+		if staticDir == "" {
+			files = append(files, "static/email-templates", "static/public:/public")
+		}
+
 		fs, err = stuffbin.NewLocalFS("/", files...)
 		if err != nil {
 			lo.Fatalf("failed to initialize local file for assets: %v", err)