diff --git a/microblog.go b/microblog.go index 9b12268..fa33a91 100644 --- a/microblog.go +++ b/microblog.go @@ -19,8 +19,29 @@ import ( const articlesDir = "data/articles" func main() { - http.HandleFunc("/", handlePage) - println("Server läuft auf http://localhost:8085") + //http.HandleFunc("/", handlePage) + println("Server startet http://localhost:8085") + + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + path := r.URL.Path + ext := filepath.Ext(path) + + switch ext { + case ".css": + w.Header().Set("Content-Type", "text/css") + case ".jpg", ".jpeg": + w.Header().Set("Content-Type", "image/jpeg") + case ".png": + w.Header().Set("Content-Type", "image/png") + case ".gif": + w.Header().Set("Content-Type", "image/gif") + default: + handlePage + } + + http.ServeFile(w, r, "."+path) + }) + http.ListenAndServe(":8085", nil) }