fix: mount only mounts directories if they exist
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
# Notes
|
||||
|
||||
(new notes at the top)
|
||||
|
||||
## TODO: Incremental Watcher
|
||||
|
||||
The DAG based incremental rebuilding will require a better file watcher that can whats entire directories and automatically recheck build rules when a new file is created.
|
||||
|
||||
```go
|
||||
type WatchListener func(path string) error
|
||||
|
||||
type Watcher interface {
|
||||
// OnFileChange will register a file change listener
|
||||
OnFileChange(l WatchListener)
|
||||
|
||||
// OnFileAdded will register a file creation listener
|
||||
OnFileAdded(l WatchListener)
|
||||
|
||||
// Watch will register "path"
|
||||
Watch(path string) error
|
||||
|
||||
// Watch will register files matching "pattern" and all directories along the way for new files
|
||||
WatchPattern(pattern string) error
|
||||
}
|
||||
```
|
||||
+7
-1
@@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -73,7 +74,7 @@ func serve(c serveConfig) error {
|
||||
if event.Has(fsnotify.Write) {
|
||||
log.Printf(`[Watcher] event: %s`, event)
|
||||
|
||||
if lastRebuild.Add(50 * time.Millisecond).After(time.Now()) {
|
||||
if lastRebuild.Add(200 * time.Millisecond).After(time.Now()) {
|
||||
log.Printf(`[Watcher] too fast, skipping`)
|
||||
continue
|
||||
}
|
||||
@@ -144,6 +145,11 @@ func serve(c serveConfig) error {
|
||||
|
||||
for _, m := range c.mounts {
|
||||
if strings.HasSuffix(m.route, "/") {
|
||||
s, _ := os.Stat(m.path)
|
||||
if s == nil || !s.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
log.Printf(`[FileServer] mounting directory "%s" on "%s"`, m.path, m.route)
|
||||
r.Handle(m.route+"*", http.StripPrefix(m.route, http.FileServer(http.Dir(m.path))))
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user