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.
This commit is contained in:
Kailash Nadh 2021-05-16 15:53:30 +05:30
parent aa5eff915d
commit d695bb34cc
1 changed files with 5 additions and 4 deletions

View File

@ -126,10 +126,6 @@ func initFS(staticDir, i18nDir string) stuffbin.FileSystem {
"config.toml.sample", "config.toml.sample",
"queries.sql", "queries.sql",
"schema.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 // The frontend app's static assets are aliased to /frontend
// so that they are accessible at /frontend/js/* etc. // so that they are accessible at /frontend/js/* etc.
@ -139,6 +135,11 @@ func initFS(staticDir, i18nDir string) stuffbin.FileSystem {
"i18n:/i18n", "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...) fs, err = stuffbin.NewLocalFS("/", files...)
if err != nil { if err != nil {
lo.Fatalf("failed to initialize local file for assets: %v", err) lo.Fatalf("failed to initialize local file for assets: %v", err)