2018-05-06 11:53:19 +02:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2018-05-08 14:57:08 +02:00
|
|
|
"github.com/gobuffalo/packr"
|
2018-05-06 11:53:19 +02:00
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2018-05-15 13:30:37 +02:00
|
|
|
func (api *API) Routes() *mux.Router {
|
2018-05-06 11:53:19 +02:00
|
|
|
// register routes
|
|
|
|
r := mux.NewRouter()
|
2018-05-15 13:30:37 +02:00
|
|
|
r.Handle("/collect", api.NewCollectHandler()).Methods(http.MethodGet)
|
|
|
|
r.Handle("/api/session", HandlerFunc(api.LoginHandler)).Methods(http.MethodPost)
|
|
|
|
r.Handle("/api/session", HandlerFunc(api.LogoutHandler)).Methods(http.MethodDelete)
|
2018-05-06 11:53:19 +02:00
|
|
|
|
2018-06-04 12:53:17 +02:00
|
|
|
r.Handle("/api/stats/site", api.Authorize(HandlerFunc(api.GetSiteStatsHandler))).Methods(http.MethodGet)
|
2018-05-22 12:23:17 +02:00
|
|
|
r.Handle("/api/stats/site/groupby/day", api.Authorize(HandlerFunc(api.GetSiteStatsPerDayHandler))).Methods(http.MethodGet)
|
2018-05-15 13:30:37 +02:00
|
|
|
r.Handle("/api/stats/site/pageviews", api.Authorize(HandlerFunc(api.GetSiteStatsPageviewsHandler))).Methods(http.MethodGet)
|
|
|
|
r.Handle("/api/stats/site/visitors", api.Authorize(HandlerFunc(api.GetSiteStatsVisitorsHandler))).Methods(http.MethodGet)
|
|
|
|
r.Handle("/api/stats/site/duration", api.Authorize(HandlerFunc(api.GetSiteStatsDurationHandler))).Methods(http.MethodGet)
|
|
|
|
r.Handle("/api/stats/site/bounces", api.Authorize(HandlerFunc(api.GetSiteStatsBouncesHandler))).Methods(http.MethodGet)
|
|
|
|
r.Handle("/api/stats/site/realtime", api.Authorize(HandlerFunc(api.GetSiteStatsRealtimeHandler))).Methods(http.MethodGet)
|
2018-05-06 11:53:19 +02:00
|
|
|
|
2018-05-15 13:30:37 +02:00
|
|
|
r.Handle("/api/stats/pages", api.Authorize(HandlerFunc(api.GetPageStatsHandler))).Methods(http.MethodGet)
|
|
|
|
r.Handle("/api/stats/pages/pageviews", api.Authorize(HandlerFunc(api.GetPageStatsPageviewsHandler))).Methods(http.MethodGet)
|
2018-05-11 15:49:37 +02:00
|
|
|
|
2018-05-15 13:30:37 +02:00
|
|
|
r.Handle("/api/stats/referrers", api.Authorize(HandlerFunc(api.GetReferrerStatsHandler))).Methods(http.MethodGet)
|
|
|
|
r.Handle("/api/stats/referrers/pageviews", api.Authorize(HandlerFunc(api.GetReferrerStatsPageviewsHandler))).Methods(http.MethodGet)
|
2018-05-07 17:01:20 +02:00
|
|
|
|
2018-05-14 12:08:18 +02:00
|
|
|
// static assets & 404 handler
|
2018-05-29 14:52:34 +02:00
|
|
|
box := packr.NewBox("./../../assets/build")
|
2018-05-14 12:08:18 +02:00
|
|
|
r.Path("/tracker.js").Handler(serveFileHandler(&box, "js/tracker.js"))
|
|
|
|
r.Path("/").Handler(serveFileHandler(&box, "index.html"))
|
2018-05-14 11:17:41 +02:00
|
|
|
r.PathPrefix("/assets").Handler(http.StripPrefix("/assets", http.FileServer(box)))
|
2018-05-14 12:08:18 +02:00
|
|
|
r.NotFoundHandler = NotFoundHandler(&box)
|
2018-05-14 11:17:41 +02:00
|
|
|
|
2018-05-14 12:08:18 +02:00
|
|
|
return r
|
2018-05-14 11:17:41 +02:00
|
|
|
}
|