Skip to content

Commit

Permalink
Prioritise --static-dir on init when no assets are embedded.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
knadh committed May 16, 2021
1 parent aa5eff9 commit d695bb3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cmd/init.go
Expand Up @@ -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.
Expand All @@ -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)
Expand Down

0 comments on commit d695bb3

Please sign in to comment.