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: Raise error if waved cannot find public/private dir #2130 #2213

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io/ioutil"
"log"
"net/http"
"os"
"path"
"path/filepath"
"strings"
Expand Down Expand Up @@ -70,6 +71,13 @@ func printLaunchBar(addr, baseURL string, isTLS bool) {
log.Println("# └" + bar + "┘")
}

// check if the directory is accessible
func checkDirectory(path string) {
if _, err := os.Stat(path); os.IsNotExist(err) {
mturoci marked this conversation as resolved.
Show resolved Hide resolved
log.Fatalf("Directory does not exist: %s", path)
mturoci marked this conversation as resolved.
Show resolved Hide resolved
}
}

// Run runs the HTTP server.
func Run(conf ServerConf) {
for _, line := range strings.Split(fmt.Sprintf(logo, conf.Version, conf.BuildDate), "\n") {
Expand Down Expand Up @@ -112,11 +120,15 @@ func Run(conf ServerConf) {
fileDir := filepath.Join(conf.DataDir, "f")
handle("_f/", newFileServer(fileDir, conf.Keychain, auth, conf.BaseURL+"_f"))
for _, dir := range conf.PrivateDirs {

checkDirectory(dir)
prefix, src := splitDirMapping(dir)
echo(Log{"t": "private_dir", "source": src, "address": prefix})
handle(prefix, http.StripPrefix(conf.BaseURL+prefix, newDirServer(src, conf.Keychain, auth)))
}
for _, dir := range conf.PublicDirs {

checkDirectory(dir)
prefix, src := splitDirMapping(dir)
echo(Log{"t": "public_dir", "source": src, "address": prefix})
handle(prefix, http.StripPrefix(conf.BaseURL+prefix, http.FileServer(http.Dir(src))))
Expand Down