@@ -22,6 +22,7 @@ import (
22
22
"io/ioutil"
23
23
"log"
24
24
"net/http"
25
+ "os"
25
26
"path"
26
27
"path/filepath"
27
28
"strings"
@@ -70,6 +71,13 @@ func printLaunchBar(addr, baseURL string, isTLS bool) {
70
71
log .Println ("# └" + bar + "┘" )
71
72
}
72
73
74
+ // check if the directory is accessible
75
+ func checkDirectory (path string ) {
76
+ if _ , err := os .Stat (path ); os .IsNotExist (err ) {
77
+ log .Fatalf ("Directory does not exist: %s" , path )
78
+ }
79
+ }
80
+
73
81
// Run runs the HTTP server.
74
82
func Run (conf ServerConf ) {
75
83
for _ , line := range strings .Split (fmt .Sprintf (logo , conf .Version , conf .BuildDate ), "\n " ) {
@@ -113,20 +121,15 @@ func Run(conf ServerConf) {
113
121
handle ("_f/" , newFileServer (fileDir , conf .Keychain , auth , conf .BaseURL + "_f" ))
114
122
for _ , dir := range conf .PrivateDirs {
115
123
124
+ checkDirectory (dir )
116
125
prefix , src := splitDirMapping (dir )
117
- err := newDirServer (src , conf .Keychain , auth )
118
- if err != nil {
119
- log .Fatalf ("Failed to start server due to directory issue: %v" , err )
120
- }
121
126
echo (Log {"t" : "private_dir" , "source" : src , "address" : prefix })
122
127
handle (prefix , http .StripPrefix (conf .BaseURL + prefix , newDirServer (src , conf .Keychain , auth )))
123
128
}
124
129
for _ , dir := range conf .PublicDirs {
130
+
131
+ checkDirectory (dir )
125
132
prefix , src := splitDirMapping (dir )
126
- err := newDirServer (src , conf .Keychain , auth )
127
- if err != nil {
128
- log .Fatalf ("Failed to start server due to directory issue: %v" , err )
129
- }
130
133
echo (Log {"t" : "public_dir" , "source" : src , "address" : prefix })
131
134
handle (prefix , http .StripPrefix (conf .BaseURL + prefix , http .FileServer (http .Dir (src ))))
132
135
}
0 commit comments