@@ -192,17 +192,19 @@ func main() {
192
192
193
193
logrus .Info ("Starting GCSWeb" )
194
194
195
+ mux := http .NewServeMux ()
196
+
195
197
// Canonicalize allowed buckets.
196
198
for i := range o .allowedBuckets {
197
199
bucket := joinPath (gcsPath , o .allowedBuckets [i ])
198
200
logrus .WithField ("bucket" , bucket ).Info ("allowing bucket" )
199
- http .HandleFunc (bucket + "/" , s .gcsRequest )
200
- http .HandleFunc (bucket , func (w http.ResponseWriter , r * http.Request ) {
201
+ mux .HandleFunc (bucket + "/" , s .gcsRequest )
202
+ mux .HandleFunc (bucket , func (w http.ResponseWriter , r * http.Request ) {
201
203
http .Redirect (w , r , bucket + "/" , http .StatusPermanentRedirect )
202
204
})
203
205
}
204
206
// Handle unknown buckets.
205
- http .HandleFunc ("/gcs/" , unknownBucketRequest )
207
+ mux .HandleFunc ("/gcs/" , unknownBucketRequest )
206
208
207
209
// Serve icons and styles.
208
210
longCacheServer := func (h http.Handler ) http.HandlerFunc {
@@ -217,25 +219,25 @@ func main() {
217
219
}
218
220
219
221
if o .flIcons != "" { // If user specifies custom icons path then read it at runtime
220
- http .Handle ("/icons/" , longCacheServer (http .StripPrefix ("/icons/" , http .FileServer (http .Dir (o .flIcons )))))
222
+ mux .Handle ("/icons/" , longCacheServer (http .StripPrefix ("/icons/" , http .FileServer (http .Dir (o .flIcons )))))
221
223
} else {
222
- http .Handle ("/icons/" , longCacheServer (http .FileServer (http .FS (embededStatic ))))
224
+ mux .Handle ("/icons/" , longCacheServer (http .FileServer (http .FS (embededStatic ))))
223
225
}
224
226
if o .flStyles != "" { // If user specifies custom styles path then read it at runtime
225
- http .Handle ("/styles/" , longCacheServer (http .StripPrefix ("/styles/" , http .FileServer (http .Dir (o .flStyles )))))
227
+ mux .Handle ("/styles/" , longCacheServer (http .StripPrefix ("/styles/" , http .FileServer (http .Dir (o .flStyles )))))
226
228
} else {
227
- http .Handle ("/styles/" , longCacheServer (http .FileServer (http .FS (embededStatic ))))
229
+ mux .Handle ("/styles/" , longCacheServer (http .FileServer (http .FS (embededStatic ))))
228
230
}
229
231
230
232
// Serve HTTP.
231
- http .HandleFunc ("/robots.txt" , robotsRequest )
232
- http .HandleFunc ("/" , otherRequest )
233
+ mux .HandleFunc ("/robots.txt" , robotsRequest )
234
+ mux .HandleFunc ("/" , otherRequest )
233
235
234
236
health := pjutil .NewHealthOnPort (o .instrumentationOptions .HealthPort )
235
237
health .ServeReady ()
236
238
237
239
logrus .Infof ("serving on port %d" , o .flPort )
238
- if err := http .ListenAndServe (fmt .Sprintf (":%d" , o .flPort ), nil ); err != nil {
240
+ if err := http .ListenAndServe (fmt .Sprintf (":%d" , o .flPort ), mux ); err != nil {
239
241
logrus .WithError (err ).Fatal ("couldn't start the http server" )
240
242
}
241
243
}
0 commit comments