Skip to content
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

Merged
merged 2 commits into from
Jan 29, 2025

Conversation

CtrlSpice
Copy link
Owner

  • SERVE_FROM_FS and STATIC_DIR get passed in as envars, for real this time
  • The server environment env is read when we instantiate the server
  • Server.Handler and Server.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.
  • I added some time to the browser opening delay, and fixed the bug I introduced in the last PR.

@CtrlSpice CtrlSpice requested a review from jmorrell January 28, 2025 21:31
Copy link
Collaborator

@jmorrell jmorrell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A capybara in a filing cabinet

Comment on lines 26 to 28
type ServerEnv struct {
ServeFromFS bool
StaticDir string
Copy link
Collaborator

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.

Copy link
Owner Author

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.

Copy link
Collaborator

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.

Comment on lines 141 to 156
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,
}
}
Copy link
Collaborator

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

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah alright!

Base automatically changed from fix-local-dev to main January 29, 2025 20:01
@CtrlSpice CtrlSpice merged commit 50bc41b into main Jan 29, 2025
2 checks passed
@CtrlSpice CtrlSpice deleted the serve-from-fs branch January 29, 2025 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants