Skip to content

Commit

Permalink
feat(serve): Reqire a specific environment variable to read external …
Browse files Browse the repository at this point in the history
…files
  • Loading branch information
etu committed Jun 8, 2024
1 parent a5449ad commit d2eafe3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export CGO_ENABLED=0
export GOPROCMGR_ALLOW_EXTERNAL_RESOURCES=1

use flake
12 changes: 9 additions & 3 deletions serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ func (serve *Serve) newRouter() *mux.Router {

serveFile := func(fileName string, contentType string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if _, err := os.Stat(fileName); err == nil {
http.ServeFile(w, r, fileName)
return
// Look for the environment variable GOPROCMGR_ALLOW_EXTERNAL_RESOURCES
// to allow serving files from the filesystem.
allowExternalResources := os.Getenv("GOPROCMGR_ALLOW_EXTERNAL_RESOURCES")

if allowExternalResources == "1" {
if _, err := os.Stat(fileName); err == nil {
http.ServeFile(w, r, fileName)
return
}
}

file, _ := static.ReadFile(fileName)
Expand Down

0 comments on commit d2eafe3

Please sign in to comment.