-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: serve front end from filesystem during development #164
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type ServerEnv struct { | ||
ServeFromFS bool | ||
StaticDir string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need both of these? What if we gated based on StaticDir != ""
? Or we can derive both from one env var.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we can, but I need to come up with a better name for it. Any ideas would be greatly appreciated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StaticDir
works just fine for me. StaticAssetsDir
if you want to be more specific? You can keep it in the ServerEnv
struct.
func getServerEnv() ServerEnv { | ||
serveFromFS, err := strconv.ParseBool(os.Getenv("SERVE_FROM_FS")) | ||
if err != nil { | ||
serveFromFS = false | ||
} | ||
|
||
staticDir := os.Getenv("STATIC_DIR") | ||
if staticDir == "" { | ||
serveFromFS = false | ||
} | ||
|
||
return ServerEnv{ | ||
ServeFromFS: serveFromFS, | ||
StaticDir: staticDir, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use os.LookupEnv
instead and make this a little cleaner I think
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah alright!
50da567
to
bad2c6e
Compare
SERVE_FROM_FS
andSTATIC_DIR
get passed in as envars, for real this timeenv
is read when we instantiate the serverServer.Handler
andServer.IndexHandler
now use the server environment instead of reading envars or getting the data as an argument. I find it cleaner this way but I'm not overly attached to it.