converting to IndexedDB
This commit is contained in:
20
main.go
20
main.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user