Fixed some bugs pertaining to new pages

This commit is contained in:
Caleb Gardner
2024-08-06 18:35:34 -05:00
parent f99c9bd2fb
commit 65a1834e9d
3 changed files with 18 additions and 11 deletions
+11 -5
View File
@@ -6,6 +6,8 @@ import (
"flag"
"log"
"net/http"
"net/http/httputil"
"net/url"
"os"
"path"
"path/filepath"
@@ -85,13 +87,15 @@ func setupBackend(mux *http.ServeMux) {
}
func setupWebsite(mux *http.ServeMux) {
url, _ := url.Parse("https://localhost:30000")
mux.Handle("rpg.darkstorm.tech/", httputil.NewSingleHostReverseProxy(url))
mux.HandleFunc("GET /files", filesRequest)
mux.HandleFunc("GET /portfolio", portfolioRequest)
mux.HandleFunc("/", mainHandle)
}
func mainHandle(w http.ResponseWriter, r *http.Request) {
path := path.Clean(r.URL.Path)
path := strings.TrimPrefix(path.Clean(r.URL.Path), "/")
if path == "/" || path == "" {
latestBlogsHandle(w, r)
return
@@ -102,10 +106,12 @@ func mainHandle(w http.ResponseWriter, r *http.Request) {
return
}
spl := strings.Split(path, "/")
stat, err = os.Stat(filepath.Join(*webRoot, spl[0]))
if err == nil && stat.IsDir() {
http.ServeFile(w, r, filepath.Join(*webRoot, spl[0], "index.html"))
return
if len(spl) > 1 {
stat, err = os.Stat(filepath.Join(*webRoot, spl[0]))
if err == nil && stat.IsDir() {
http.ServeFile(w, r, filepath.Join(*webRoot, spl[0], "index.html"))
return
}
}
blogHandle(w, r, path)
}