@@ -20,15 +20,15 @@ import "github.com/gorilla/websocket"
20
20
An optional argument to pass a root domain and find/replace
21
21
it inside the html file content, so you can develop with
22
22
absolute paths. Not a high priority, because my static site
23
- builder (qxoko /spindle) solves this problem for me.
23
+ builder (lichendust /spindle) solves this problem for me.
24
24
25
25
# Get rid of gorilla/websocket
26
26
27
27
It's supposedly possible to do this without using a middleware
28
28
library, just with net/http. I haven't tried it. I might do.
29
29
*/
30
30
31
- const TOIL = "Toil v0.1.1 "
31
+ const TOIL = "Toil v0.1.3 "
32
32
33
33
const SERVE_PORT = ":3456"
34
34
const RELOAD_PREFIX = "/_toil/"
@@ -80,17 +80,19 @@ func main() {
80
80
does_exist , is_dir := exists (incoming_path )
81
81
82
82
if does_exist && is_dir {
83
- incoming_path = filepath .ToSlash (filepath .Join (incoming_path , "index.html" ))
84
- does_exist , _ = exists (incoming_path )
85
- } else {
86
- incoming_path += ".html"
87
- does_exist , _ = exists (incoming_path )
83
+ index_path := filepath .ToSlash (filepath .Join (incoming_path , "index.html" ))
84
+ index_exists , _ := exists (index_path )
85
+
86
+ if index_exists {
87
+ serve_file (w , index_path )
88
+ return
89
+ }
88
90
}
89
91
92
+ incoming_path += ".html"
93
+ does_exist , _ = exists (incoming_path )
90
94
if does_exist {
91
- // is this a good way to do it? who knows
92
- file_bytes := bytes .Replace (load_file (incoming_path ), []byte ("</head>" ), []byte (RELOAD_SCRIPT ), 1 )
93
- w .Write ([]byte (file_bytes ))
95
+ serve_file (w , incoming_path )
94
96
return
95
97
}
96
98
@@ -160,6 +162,11 @@ func open_browser(port string) {
160
162
println (url )
161
163
}
162
164
165
+ func serve_file (w http.ResponseWriter , file_name string ) {
166
+ file_bytes := bytes .Replace (load_file (file_name ), []byte ("</head>" ), []byte (RELOAD_SCRIPT ), 1 )
167
+ w .Write ([]byte (file_bytes ))
168
+ }
169
+
163
170
func exists (file string ) (bool , bool ) {
164
171
f , err := os .Stat (file )
165
172
if err != nil {
0 commit comments