@@ -24,7 +24,6 @@ import (
24
24
"fmt"
25
25
"html/template"
26
26
"io"
27
- "io/ioutil"
28
27
"net/http"
29
28
"os"
30
29
"os/exec"
@@ -73,7 +72,6 @@ var addr = flag.String("a", "127.0.0.1", "Address of server host.")
73
72
var port = flag .Int ("p" , 8000 , "Port of server host." )
74
73
var cmdBufLen = 1024
75
74
var browserAddr = "127.0.0.1"
76
- var rootmarker = ".webapp"
77
75
var settings lib.UserSetting
78
76
var id = "webapp"
79
77
@@ -134,13 +132,15 @@ func main() {
134
132
options = lib.CmdOptions {* staticRoot , * browseRoot , * appsRoot , * scionRoot , * scionBin , * scionGen , * scionGenCache , * scionLogs }
135
133
// correct static files are required for the app to serve them, else fail
136
134
if _ , err := os .Stat (path .Join (options .StaticRoot , "static" )); os .IsNotExist (err ) {
137
- log .Error ("-s flag must be set with local repo: scion-apps/webapp" )
135
+ log .Error ("-s flag must be set with local repo: scion-apps/webapp/web " )
138
136
CheckFatal (err )
139
137
return
140
138
}
139
+ checkPath (options .StaticRoot )
141
140
142
141
// logging
143
142
logDirPath := ensurePath (options .StaticRoot , "logs" )
143
+ checkPath (options .ScionLogs )
144
144
log .Root ().SetHandler (log .MultiHandler (
145
145
log .LvlFilterHandler (log .LvlDebug ,
146
146
log .StreamHandler (os .Stderr , fmt15 .Fmt15Format (fmt15 .ColorMap ))),
@@ -149,15 +149,6 @@ func main() {
149
149
fmt15 .Fmt15Format (nil )))))
150
150
log .Info ("======================> Webapp started" )
151
151
152
- checkPath (options .StaticRoot )
153
- checkPath (options .BrowseRoot )
154
- checkPath (options .AppsRoot )
155
- checkPath (options .ScionRoot )
156
- checkPath (options .ScionBin )
157
- checkPath (options .ScionGen )
158
- checkPath (options .ScionGenCache )
159
- checkPath (options .ScionLogs )
160
-
161
152
// prepare templates
162
153
templates = prepareTemplates (options .StaticRoot )
163
154
// open and manage database
@@ -175,14 +166,18 @@ func main() {
175
166
ensurePath (options .StaticRoot , "data" )
176
167
ensurePath (options .StaticRoot , "data/images" )
177
168
169
+ checkPath (options .ScionRoot )
170
+ checkPath (options .ScionGen )
171
+ checkPath (options .ScionGenCache )
178
172
initLocalIaOptions ()
179
173
log .Info ("IA loaded:" , "myIa" , settings .MyIA )
180
174
181
175
// generate client/server default
182
176
lib .GenClientNodeDefaults (& options , settings .MyIA )
183
177
lib .GenServerNodeDefaults (& options , localIAs )
184
178
185
- refreshRootDirectory ()
179
+ checkPath (options .AppsRoot )
180
+ checkPath (options .ScionBin )
186
181
appsBuildCheck ("bwtester" )
187
182
appsBuildCheck ("camerapp" )
188
183
appsBuildCheck ("sensorapp" )
@@ -191,6 +186,7 @@ func main() {
191
186
192
187
initServeHandlers ()
193
188
log .Info (fmt .Sprintf ("Browser access: at http://%s:%d." , browserAddr , * port ))
189
+ checkPath (options .BrowseRoot )
194
190
log .Info ("File browser root:" , "root" , options .BrowseRoot )
195
191
log .Info (fmt .Sprintf ("Listening on %s:%d..." , * addr , * port ))
196
192
err = http .ListenAndServe (fmt .Sprintf ("%s:%d" , * addr , * port ), logRequestHandler (http .DefaultServeMux ))
@@ -581,13 +577,13 @@ func getClientCwd(app string) string {
581
577
var cwd string
582
578
switch app {
583
579
case "sensorapp" :
584
- cwd = path .Join (options .StaticRoot , ". " )
580
+ cwd = path .Join (options .StaticRoot , "data " )
585
581
case "camerapp" :
586
582
cwd = path .Join (options .StaticRoot , "data/images" )
587
583
case "bwtester" :
588
- cwd = path .Join (options .StaticRoot , ". " )
584
+ cwd = path .Join (options .StaticRoot , "data " )
589
585
case "echo" , "traceroute" :
590
- cwd = path .Join (options .ScionRoot , "bin " )
586
+ cwd = path .Join (options .ScionBin , ". " )
591
587
}
592
588
return cwd
593
589
}
@@ -788,33 +784,3 @@ func setUserOptionsHandler(w http.ResponseWriter, r *http.Request) {
788
784
lib .GenClientNodeDefaults (& options , settings .MyIA )
789
785
log .Info ("IA set:" , "myIa" , settings .MyIA )
790
786
}
791
-
792
- // Used to workaround cache-control issues by ensuring root specified by user
793
- // has updated last modified date by writing a .webapp file
794
- func refreshRootDirectory () {
795
- cliFp := path .Join (options .StaticRoot , options .BrowseRoot , rootmarker )
796
- err := ioutil .WriteFile (cliFp , []byte (`` ), 0644 )
797
- CheckError (err )
798
- }
799
-
800
- // FileBrowseResponseWriter holds modified response headers
801
- type FileBrowseResponseWriter struct {
802
- http.ResponseWriter
803
- }
804
-
805
- // WriteHeader prevents caching directory listings based on directory last modified date.
806
- // This is especially a problem in Chrome, and can serve the browser stale listings.
807
- func (w FileBrowseResponseWriter ) WriteHeader (code int ) {
808
- if code == 200 {
809
- w .Header ().Add ("Cache-Control" , "no-cache, no-store, must-revalidate, proxy-revalidate" )
810
- }
811
- w .ResponseWriter .WriteHeader (code )
812
- }
813
-
814
- // Handles custom filtering of file browsing content
815
- func fileBrowseHandler (h http.Handler ) http.Handler {
816
- return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
817
- rw := FileBrowseResponseWriter {w }
818
- h .ServeHTTP (rw , r )
819
- })
820
- }
0 commit comments