fix: provide content type for any other result
This commit is contained in:
parent
4a4552b944
commit
2323cf3f89
3
main.go
3
main.go
|
@ -17,6 +17,7 @@ import (
|
||||||
var baseDirectory string
|
var baseDirectory string
|
||||||
|
|
||||||
func handler(w http.ResponseWriter, r *http.Request) {
|
func handler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
log.Printf("Incoming request: %s %s", r.Method, r.URL.Path)
|
||||||
filePath := path.Join(baseDirectory, r.URL.Path)
|
filePath := path.Join(baseDirectory, r.URL.Path)
|
||||||
file, err := os.Stat(filePath)
|
file, err := os.Stat(filePath)
|
||||||
if err == nil && !file.IsDir() {
|
if err == nil && !file.IsDir() {
|
||||||
|
@ -29,6 +30,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Add("Content-Type", t)
|
w.Header().Add("Content-Type", t)
|
||||||
http.ServeFile(w, r, gz)
|
http.ServeFile(w, r, gz)
|
||||||
} else {
|
} else {
|
||||||
|
w.Header().Add("Content-Type", t)
|
||||||
http.ServeFile(w, r, filePath)
|
http.ServeFile(w, r, filePath)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -37,6 +39,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
||||||
file, err := os.Stat(index)
|
file, err := os.Stat(index)
|
||||||
if err == nil && !file.IsDir() {
|
if err == nil && !file.IsDir() {
|
||||||
// index.html exists
|
// index.html exists
|
||||||
|
w.Header().Add("Content-Type", "text/html")
|
||||||
http.ServeFile(w, r, index)
|
http.ServeFile(w, r, index)
|
||||||
} else {
|
} else {
|
||||||
// index.html does not exist
|
// index.html does not exist
|
||||||
|
|
Loading…
Reference in New Issue