2016-11-21 12:24:50 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2016-11-22 20:02:06 +00:00
|
|
|
"os"
|
2016-11-22 21:33:50 +00:00
|
|
|
"log"
|
2016-11-21 12:24:50 +00:00
|
|
|
"github.com/dannyvankooten/ana/core"
|
|
|
|
"github.com/dannyvankooten/ana/api"
|
2016-11-22 19:57:16 +00:00
|
|
|
"github.com/gorilla/mux"
|
2016-11-22 20:02:06 +00:00
|
|
|
"github.com/gorilla/handlers"
|
2016-11-22 21:33:50 +00:00
|
|
|
"github.com/joho/godotenv"
|
2016-11-21 12:24:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-11-24 12:10:40 +00:00
|
|
|
|
2016-11-22 21:33:50 +00:00
|
|
|
// test .env file
|
|
|
|
err := godotenv.Load()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Error loading .env file")
|
|
|
|
}
|
|
|
|
|
|
|
|
db := core.SetupDatabaseConnection()
|
|
|
|
defer db.Close()
|
2016-11-21 12:24:50 +00:00
|
|
|
|
2016-11-22 21:33:50 +00:00
|
|
|
r := mux.NewRouter()
|
2016-11-22 19:57:16 +00:00
|
|
|
|
2016-11-22 21:33:50 +00:00
|
|
|
// register routes
|
|
|
|
r.HandleFunc("/collect", api.CollectHandler).Methods("GET")
|
2016-11-23 14:51:19 +00:00
|
|
|
r.Handle("/api/session", api.Login).Methods("POST")
|
|
|
|
r.Handle("/api/session", api.Logout).Methods("DELETE")
|
2016-11-22 21:33:50 +00:00
|
|
|
r.Handle("/api/visits/count/day", api.Authorize(api.GetVisitsDayCountHandler)).Methods("GET")
|
|
|
|
r.Handle("/api/visits/count/realtime", api.Authorize(api.GetVisitsRealtimeCount)).Methods("GET")
|
|
|
|
r.Handle("/api/visits", api.Authorize(api.GetVisitsHandler)).Methods("GET")
|
2016-11-23 19:30:09 +00:00
|
|
|
r.Handle("/api/pageviews/count/day", api.Authorize(api.GetPageviewsDayCountHandler)).Methods("GET")
|
2016-11-22 21:33:50 +00:00
|
|
|
r.Handle("/api/pageviews", api.Authorize(api.GetPageviewsHandler)).Methods("GET")
|
2016-11-23 19:30:09 +00:00
|
|
|
|
2016-11-22 21:33:50 +00:00
|
|
|
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static/"))))
|
|
|
|
r.Handle("/", http.FileServer(http.Dir("./views/")))
|
2016-11-22 19:57:16 +00:00
|
|
|
|
2016-11-22 21:33:50 +00:00
|
|
|
http.ListenAndServe(":8080", handlers.LoggingHandler(os.Stdout, r))
|
2016-11-21 12:24:50 +00:00
|
|
|
}
|