From 85152fc1373efbeb65397042ed29dc7dbcc69928 Mon Sep 17 00:00:00 2001 From: Dawn Chen Date: Fri, 27 Jun 2014 16:08:35 -0700 Subject: [PATCH] Add a FileServer for master's logs --- pkg/apiserver/apiserver.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/apiserver/apiserver.go b/pkg/apiserver/apiserver.go index cabe6541b07..92cfe11c726 100644 --- a/pkg/apiserver/apiserver.go +++ b/pkg/apiserver/apiserver.go @@ -76,9 +76,10 @@ func MakeAsync(fn WorkFunc) <-chan interface{} { // // TODO: consider migrating this to go-restful which is a more full-featured version of the same thing. type ApiServer struct { - prefix string - storage map[string]RESTStorage - ops *Operations + prefix string + storage map[string]RESTStorage + ops *Operations + logserver http.Handler } // New creates a new ApiServer object. @@ -86,9 +87,10 @@ type ApiServer struct { // 'prefix' is the hosting path prefix. func New(storage map[string]RESTStorage, prefix string) *ApiServer { return &ApiServer{ - storage: storage, - prefix: prefix, - ops: NewOperations(), + storage: storage, + prefix: prefix, + ops: NewOperations(), + logserver: http.StripPrefix("/logs/", http.FileServer(http.Dir("/var/log/"))), } } @@ -120,6 +122,10 @@ func (server *ApiServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { server.handleIndex(w) return } + if strings.HasPrefix(url.Path, "/logs/") { + server.logserver.ServeHTTP(w, req) + return + } if !strings.HasPrefix(url.Path, server.prefix) { server.notFound(req, w) return