user fiber for main website

This commit is contained in:
Caleb Gardner
2023-03-11 19:06:58 -06:00
parent 3e863f360b
commit e00d2558a3
3 changed files with 102 additions and 19 deletions
+14 -17
View File
@@ -8,9 +8,9 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"os"
"path"
"strings"
"path/filepath"
"github.com/gofiber/fiber/v2"
)
func webserver() {
@@ -26,9 +26,17 @@ func webserver() {
quitChan <- "web arg"
return
}
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
http.Handle("/SWAssistant/", swaHandler{})
http.Handle("/", http.FileServer(http.Dir(path)))
go func() {
app := fiber.New()
app.Static("/", path)
app.Static("/files", filepath.Join(path, "files"), fiber.Static{
Browse: true,
})
app.Static("/SWAssistant", filepath.Join(path, "SWAssistant"))
err := app.ListenTLS(":443", filepath.Join(keyPath, "cert.pem"), filepath.Join(keyPath, "key.pem"))
log.Println("Error while serving website:", err)
quitChan <- "web err"
}()
http.Handle("rpg.darkstorm.tech/", sup{})
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
tlsConf := &tls.Config{
@@ -62,14 +70,3 @@ func (s sup) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
rvProx := httputil.NewSingleHostReverseProxy(url)
rvProx.ServeHTTP(writer, req)
}
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"))
}
}