diff options
author | Pacien TRAN-GIRARD | 2012-09-21 21:18:11 +0200 |
---|---|---|
committer | Pacien | 2015-12-07 22:48:25 +0100 |
commit | d2a687bf2ae6f6af257cebdb80ee56a4cbbd7879 (patch) | |
tree | 03922d14c8bc80bb49c48f1af58531834e37e3fa | |
parent | 20655b872242d41baeec8301e978fd52c90cc500 (diff) | |
download | ninja-go-local-cloud-d2a687bf2ae6f6af257cebdb80ee56a4cbbd7879.tar.gz |
"Manually" serve HTML files to set the correct header and to use the
correct editor.
-rw-r--r-- | src/ninjacloud.go | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/ninjacloud.go b/src/ninjacloud.go index 9f78cfb..3e1f3e3 100644 --- a/src/ninjacloud.go +++ b/src/ninjacloud.go | |||
@@ -115,10 +115,10 @@ func writeFile(path string, content []byte, overwrite bool) (err error) { | |||
115 | return | 115 | return |
116 | } | 116 | } |
117 | 117 | ||
118 | /*func readFile(path string) (content []byte, err error) { | 118 | func readFile(path string) (content []byte, err error) { |
119 | content, err = ioutil.ReadFile(path) | 119 | content, err = ioutil.ReadFile(path) |
120 | return | 120 | return |
121 | }*/ | 121 | } |
122 | 122 | ||
123 | func removeFile(path string) (err error) { | 123 | func removeFile(path string) (err error) { |
124 | err = os.Remove(path) | 124 | err = os.Remove(path) |
@@ -441,7 +441,21 @@ func fileHandler(w http.ResponseWriter, r *http.Request) { | |||
441 | w.Write(j) | 441 | w.Write(j) |
442 | return | 442 | return |
443 | } else { | 443 | } else { |
444 | http.ServeFile(w, r, p) | 444 | ext := filepath.Ext(p) |
445 | if ext == ".htm" || ext == ".html" { | ||
446 | file, err := readFile(p) | ||
447 | if err != nil { | ||
448 | log.Println(err) | ||
449 | w.WriteHeader(http.StatusInternalServerError) | ||
450 | return | ||
451 | } | ||
452 | w.Header().Set("Content-Type", "text/plain, charset=utf-8") | ||
453 | w.WriteHeader(http.StatusOK) | ||
454 | w.Write(file) | ||
455 | return | ||
456 | } else { | ||
457 | http.ServeFile(w, r, p) | ||
458 | } | ||
445 | } | 459 | } |
446 | } | 460 | } |
447 | } | 461 | } |