summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2012-09-22 18:53:40 +0200
committerPacien2015-12-07 22:48:26 +0100
commitc2a5444b9eda51d6dc6a6c001cdbd540743734d6 (patch)
tree9dcd361df2b4828c58444442468184691e1c5086
parentb926c497c832f481d3e1085e69f4283e4e92415e (diff)
downloadninja-go-local-cloud-c2a5444b9eda51d6dc6a6c001cdbd540743734d6.tar.gz
Manually serve files in order to set the Content-Type header correctly
(for HTML and JSON files).
-rw-r--r--src/ninjacloud.go27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/ninjacloud.go b/src/ninjacloud.go
index 235a9be..5f9274e 100644
--- a/src/ninjacloud.go
+++ b/src/ninjacloud.go
@@ -445,20 +445,23 @@ func fileHandler(w http.ResponseWriter, r *http.Request) {
445 return 445 return
446 } else { 446 } else {
447 ext := filepath.Ext(p) 447 ext := filepath.Ext(p)
448 if ext == ".htm" || ext == ".html" { 448 switch ext {
449 file, err := readFile(p) 449 case ".htm":
450 if err != nil { 450 case ".html":
451 log.Println(err)
452 w.WriteHeader(http.StatusInternalServerError)
453 return
454 }
455 w.Header().Set("Content-Type", "text/plain, charset=utf-8") 451 w.Header().Set("Content-Type", "text/plain, charset=utf-8")
456 w.WriteHeader(http.StatusOK) 452
457 w.Write(file) 453 case ".json":
454 w.Header().Set("Content-Type", "application/json")
455 }
456 file, err := readFile(p)
457 if err != nil {
458 log.Println(err)
459 w.WriteHeader(http.StatusInternalServerError)
458 return 460 return
459 } else {
460 http.ServeFile(w, r, p)
461 } 461 }
462 w.WriteHeader(http.StatusOK)
463 w.Write(file)
464 return
462 } 465 }
463 } 466 }
464} 467}
@@ -664,7 +667,7 @@ func main() {
664 log.Println(err) 667 log.Println(err)
665 return 668 return
666 } 669 }
667 670
668 err = createDir(projectsDir) 671 err = createDir(projectsDir)
669 if err != nil { 672 if err != nil {
670 log.Println(err) 673 log.Println(err)