2024-02-10 11:59:58 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
2024-02-11 09:15:00 +00:00
|
|
|
"os"
|
2024-02-10 11:59:58 +00:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
|
|
|
|
"code.tjo.space/mentos1386/zdravko/internal"
|
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/pages"
|
2024-02-11 10:56:21 +00:00
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/static"
|
2024-02-10 11:59:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-02-11 09:15:00 +00:00
|
|
|
port := os.Getenv("PORT")
|
|
|
|
if port == "" {
|
|
|
|
port = "8000"
|
|
|
|
}
|
|
|
|
|
2024-02-10 11:59:58 +00:00
|
|
|
r := mux.NewRouter()
|
|
|
|
|
2024-02-11 10:56:21 +00:00
|
|
|
db, err := internal.ConnectToDatabase()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
log.Println("Connected to database")
|
|
|
|
|
|
|
|
page := pages.NewPageHandler(db)
|
|
|
|
|
2024-02-10 11:59:58 +00:00
|
|
|
// Server static files
|
2024-02-11 10:56:21 +00:00
|
|
|
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.FS(static.Static))))
|
2024-02-10 11:59:58 +00:00
|
|
|
|
2024-02-11 10:56:21 +00:00
|
|
|
r.HandleFunc("/", page.Index).Methods("GET")
|
|
|
|
r.HandleFunc("/settings", page.Settings).Methods("GET")
|
2024-02-10 11:59:58 +00:00
|
|
|
|
2024-02-11 09:15:00 +00:00
|
|
|
log.Println("Server started on", port)
|
|
|
|
log.Fatal(http.ListenAndServe(":"+port, r))
|
2024-02-10 11:59:58 +00:00
|
|
|
}
|