Working on the actual web pages

This commit is contained in:
Caleb Gardner
2024-07-31 06:53:05 -05:00
parent f86cdb0554
commit 91c122e212
4 changed files with 46 additions and 5 deletions
+20 -1
View File
@@ -6,7 +6,10 @@ import (
"flag"
"log"
"net/http"
"os"
"path"
"path/filepath"
"strings"
"github.com/CalebQ42/darkstorm-server/internal/backend"
"github.com/CalebQ42/darkstorm-server/internal/backend/db"
@@ -88,5 +91,21 @@ func setupWebsite(mux *http.ServeMux) {
}
func mainHandle(w http.ResponseWriter, r *http.Request) {
path := path.Clean(r.URL.Path)
if path == "/" || path == "" {
latestBlogsHandle(w, r)
return
}
stat, err := os.Stat(filepath.Join(*webRoot, path))
if err == nil && !stat.IsDir() {
http.ServeFile(w, r, filepath.Join(*webRoot, path))
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
}
blogHandle(w, r, path)
}