2018-05-06 09:53:19 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Routes(webroot string) *mux.Router {
|
|
|
|
// register routes
|
|
|
|
r := mux.NewRouter()
|
|
|
|
r.Handle("/collect", NewCollectHandler()).Methods(http.MethodGet)
|
|
|
|
r.Handle("/api/session", LoginHandler).Methods(http.MethodPost)
|
|
|
|
r.Handle("/api/session", LogoutHandler).Methods(http.MethodDelete)
|
|
|
|
|
2018-05-07 14:05:53 +00:00
|
|
|
r.Handle("/api/stats/site/pageviews", Authorize(GetSiteStatsPageviewsHandler)).Methods(http.MethodGet)
|
|
|
|
r.Handle("/api/stats/site/visitors", Authorize(GetSiteStatsVisitorsHandler)).Methods(http.MethodGet)
|
|
|
|
r.Handle("/api/stats/site/duration", Authorize(GetSiteStatsDurationHandler)).Methods(http.MethodGet)
|
|
|
|
r.Handle("/api/stats/site/bounces", Authorize(GetSiteStatsBouncesHandler)).Methods(http.MethodGet)
|
|
|
|
r.Handle("/api/stats/site/realtime", Authorize(GetSiteStatsRealtimeHandler)).Methods(http.MethodGet)
|
2018-05-06 09:53:19 +00:00
|
|
|
|
2018-05-07 15:01:20 +00:00
|
|
|
r.Handle("/api/stats/page", Authorize(GetPageStatsHandler)).Methods(http.MethodGet)
|
|
|
|
|
2018-05-06 09:53:19 +00:00
|
|
|
r.Path("/tracker.js").Handler(http.FileServer(http.Dir(webroot + "/js/")))
|
|
|
|
r.PathPrefix("/").Handler(http.FileServer(http.Dir(webroot)))
|
|
|
|
return r
|
|
|
|
}
|