first commit
This commit is contained in:
58
main.go
Normal file
58
main.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"slideshowApp/env"
|
||||
"slideshowApp/handlers"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
env.Load(".env")
|
||||
|
||||
r := mux.NewRouter()
|
||||
|
||||
uploadFolder := env.PhotoDir.GetValue()
|
||||
|
||||
if _, err := os.Stat(uploadFolder); err != nil {
|
||||
fmt.Println("upload folder for images not found: ", uploadFolder)
|
||||
fmt.Println("use fallback")
|
||||
uploadFolder = "./images"
|
||||
|
||||
}
|
||||
|
||||
fmt.Println("upload folder for images: ", uploadFolder)
|
||||
r.PathPrefix("/uploads/").Handler(http.StripPrefix("/uploads/", http.FileServer(http.Dir(uploadFolder))))
|
||||
r.HandleFunc("/api/images", handlers.ListFilesHandler).Methods("GET")
|
||||
r.HandleFunc("/ws", handlers.Websocket)
|
||||
r.HandleFunc("/upload", handlers.UploadHandler).Methods("POST")
|
||||
r.HandleFunc("/settings", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "settings.html") })
|
||||
r.HandleFunc("/api/save-schedule", handlers.SaveSchedule).Methods("POST")
|
||||
r.HandleFunc("/api/get-schedule", handlers.GetSchedule).Methods("GET")
|
||||
|
||||
r.HandleFunc("/api/delete", handlers.DeleteHandler).Methods("POST")
|
||||
r.HandleFunc("/manage", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "manage.html")
|
||||
})
|
||||
|
||||
r.HandleFunc("/api/info", handlers.InfoHandler).Methods("GET")
|
||||
|
||||
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "index.html")
|
||||
})
|
||||
// We add a route for the slideshow page specifically
|
||||
r.HandleFunc("/slideshow", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "frame.html")
|
||||
})
|
||||
|
||||
host := env.Host.GetValue()
|
||||
port := env.Port.GetValue()
|
||||
url := fmt.Sprintf("%s:%s", host, port)
|
||||
fmt.Println("Server running at", url)
|
||||
log.Fatal(http.ListenAndServe(url, r))
|
||||
}
|
||||
Reference in New Issue
Block a user