60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"slideshowApp/env"
|
|
"slideshowApp/handlers"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
var staticFolder = "./web/static/"
|
|
|
|
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, staticFolder+"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, staticFolder+"manage.html")
|
|
})
|
|
|
|
r.HandleFunc("/api/info", handlers.InfoHandler).Methods("GET")
|
|
|
|
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
http.ServeFile(w, r, staticFolder+"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, staticFolder+"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))
|
|
}
|