Small changes to serve SWAssistant better
This commit is contained in:
@@ -4,6 +4,9 @@ import (
|
||||
"flag"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func webserver() {
|
||||
@@ -19,8 +22,21 @@ func webserver() {
|
||||
quitChan <- "web arg"
|
||||
return
|
||||
}
|
||||
http.Handle("/SWAssistant/", swaHandler{})
|
||||
http.Handle("/", http.FileServer(http.Dir(path)))
|
||||
err := http.ListenAndServeTLS(":443", keyPath+"/cert.pem", keyPath+"/key.pem", nil)
|
||||
log.Println("Error while serving website:", err)
|
||||
quitChan <- "web err"
|
||||
}
|
||||
|
||||
type swaHandler struct {
|
||||
}
|
||||
|
||||
func (s swaHandler) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
|
||||
if _, err := os.Open(path.Join(flag.Arg(0) + req.URL.EscapedPath())); strings.Contains(req.URL.EscapedPath(), "#") || err == nil {
|
||||
http.FileServer(http.Dir(flag.Arg(0))).ServeHTTP(writer, req)
|
||||
} else {
|
||||
http.Redirect(writer, req, "https://darkstorm.tech/SWAssistant/#"+strings.TrimPrefix(req.URL.EscapedPath(), "/SWAssistant"), http.StatusFound)
|
||||
// log.Println("https://darkstorm.tech/SWAssistant/#" + strings.TrimPrefix(req.URL.EscapedPath(), "/SWAssistant"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user