set content-type for files
This commit is contained in:
+23
-2
@@ -19,8 +19,29 @@ import (
|
|||||||
const articlesDir = "data/articles"
|
const articlesDir = "data/articles"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
http.HandleFunc("/", handlePage)
|
//http.HandleFunc("/", handlePage)
|
||||||
println("Server läuft auf http://localhost:8085")
|
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)
|
http.ListenAndServe(":8085", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user