Small changes to serve SWAssistant better
This commit is contained in:
@@ -2,4 +2,4 @@ module github.com/CalebQ42/darkstorm-server
|
|||||||
|
|
||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
require github.com/1lann/udp-forward v0.0.0-20191015034046-6b774a53ea39 // indirect
|
require github.com/1lann/udp-forward v0.0.0-20191015034046-6b774a53ea39
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func webserver() {
|
func webserver() {
|
||||||
@@ -19,8 +22,21 @@ func webserver() {
|
|||||||
quitChan <- "web arg"
|
quitChan <- "web arg"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
http.Handle("/SWAssistant/", swaHandler{})
|
||||||
http.Handle("/", http.FileServer(http.Dir(path)))
|
http.Handle("/", http.FileServer(http.Dir(path)))
|
||||||
err := http.ListenAndServeTLS(":443", keyPath+"/cert.pem", keyPath+"/key.pem", nil)
|
err := http.ListenAndServeTLS(":443", keyPath+"/cert.pem", keyPath+"/key.pem", nil)
|
||||||
log.Println("Error while serving website:", err)
|
log.Println("Error while serving website:", err)
|
||||||
quitChan <- "web 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