StarlioX/main.go

55 lines
1.7 KiB
Go
Raw Normal View History

2022-09-18 19:29:08 +03:00
package main
import (
"net/http"
"github.com/Redume/EveryNasa/api/controllers"
"github.com/Redume/EveryNasa/functions"
"github.com/Redume/EveryNasa/web/pages"
2022-09-19 13:23:39 +03:00
"github.com/getlantern/systray"
2022-09-18 19:29:08 +03:00
"github.com/gorilla/mux"
)
func main() {
2022-10-02 12:24:00 +03:00
go functions.Logger("EveryNasa started")
2022-09-18 19:29:08 +03:00
go functions.Database()
go systray.Run(functions.Tray, functions.Quit)
go functions.StartWallpaper()
router := mux.NewRouter()
router.Use(func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
2022-09-21 10:48:05 +03:00
w.Header().Set("Access-Control-Allow-Methods", "POST, GET")
2022-09-18 19:29:08 +03:00
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
next.ServeHTTP(w, r)
})
})
2022-10-02 12:24:00 +03:00
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./web/static"))))
http.HandleFunc("/", page.GalleryHandler)
http.HandleFunc("/settings", page.SettingsHandler)
http.HandleFunc("/about", page.AboutHandler)
2022-09-18 19:29:08 +03:00
router.HandleFunc("/api/get/settings", controllers.SettingsGet).Methods("GET")
router.HandleFunc("/api/get/version", controllers.Version).Methods("GET")
2022-10-02 12:24:00 +03:00
2022-09-18 19:29:08 +03:00
router.HandleFunc("/api/update/settings", controllers.SettingsUpdate).Methods("POST")
2022-09-19 02:08:26 +03:00
router.HandleFunc("/api/update/wallpaper", controllers.WallpaperUpdate).Methods("POST")
2022-10-02 12:24:00 +03:00
router.HandleFunc("/api/update/startup", controllers.Startup).Methods("POST")
router.HandleFunc("/api/create/label", controllers.CreateLabel).Methods("POST")
2022-09-18 19:29:08 +03:00
go func() {
2022-09-21 10:48:05 +03:00
err := http.ListenAndServe(":4662", nil)
2022-09-18 19:29:08 +03:00
if err != nil {
2022-09-25 11:10:27 +03:00
functions.Logger(err.Error())
2022-09-18 19:29:08 +03:00
}
}()
2022-09-21 10:48:05 +03:00
err := http.ListenAndServe(":8080", router)
2022-09-18 19:29:08 +03:00
if err != nil {
2022-09-25 11:10:27 +03:00
functions.Logger(err.Error())
2022-09-18 19:29:08 +03:00
}
}