converting to IndexedDB

This commit is contained in:
“bobbydigitales”
2023-11-12 23:31:07 -08:00
parent 6cd5a04cc1
commit 41054a5dbf
5 changed files with 240 additions and 109 deletions

20
main.go
View File

@@ -3,6 +3,8 @@ package main
import (
"log"
"net/http"
"os"
"path/filepath"
"strconv"
"github.com/gorilla/websocket"
@@ -50,6 +52,18 @@ func (lh *LoggingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
lh.handler.ServeHTTP(w, r)
}
// noDirListing wraps an http.FileServer handler to prevent directory listings
func noDirListing(h http.Handler, root string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
path := filepath.Join(root, r.URL.Path)
if info, err := os.Stat(path); err == nil && info.IsDir() {
http.NotFound(w, r) // Always return 404 for directories
return
}
h.ServeHTTP(w, r)
}
}
func main() {
dir := "./"
port := 80
@@ -59,8 +73,10 @@ func main() {
// Set up file server and WebSocket endpoint
fs := http.FileServer(http.Dir(dir))
loggingHandler := &LoggingHandler{handler: fs}
http.Handle("/", loggingHandler)
// loggingHandler := &LoggingHandler{handler: fs}
// http.Handle("/", loggingHandler)
http.Handle("/", noDirListing(fs, dir))
http.HandleFunc("/ws", handleWebSocket)
// Configure and start the HTTP server