-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
29 lines (24 loc) · 804 Bytes
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package main
import (
"log"
"net/http"
)
func main() {
log.Println("Listening on :8082...")
http.HandleFunc("/", serveFiles) // "/" matches everything (See ServeMux)
log.Fatal(http.ListenAndServeTLS(":8082", "cert.crt", "key.key", nil))
}
func serveFiles(w http.ResponseWriter, r *http.Request) {
log.Printf("Request: %s\n", r.URL.Path)
var filePath = r.URL.Path[1:] //remove slash
if filePath == "" {
// On empty path display home/index (`browsertest.html`)
filePath = "browsertest.html"
} else if filePath == "browsertest.js" || filePath == "browsertest.html" || filePath == "browsertestjs.png" || filePath == "favicon.ico" {
// Do nothing, serve filepath unmodified.
} else {
filePath = "../" + filePath
}
log.Printf("Serving: %s", filePath)
http.ServeFile(w, r, filePath)
}