2016-12-08 19:45:26 +00:00
|
|
|
package commands
|
|
|
|
|
2016-12-11 13:50:01 +00:00
|
|
|
import (
|
|
|
|
"github.com/dannyvankooten/ana/api"
|
|
|
|
"github.com/gorilla/handlers"
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
2016-12-08 19:45:26 +00:00
|
|
|
)
|
|
|
|
|
2016-12-08 19:57:44 +00:00
|
|
|
func startServer() {
|
2016-12-11 13:50:01 +00:00
|
|
|
// register routes
|
|
|
|
r := mux.NewRouter()
|
|
|
|
r.HandleFunc("/collect", api.CollectHandler).Methods("GET")
|
|
|
|
r.Handle("/api/session", api.LoginHandler).Methods("POST")
|
|
|
|
r.Handle("/api/session", api.LogoutHandler).Methods("DELETE")
|
|
|
|
r.Handle("/api/visitors/count", api.Authorize(api.GetVisitorsCountHandler)).Methods("GET")
|
|
|
|
r.Handle("/api/visitors/count/group/{period}", api.Authorize(api.GetVisitorsPeriodCountHandler)).Methods("GET")
|
|
|
|
r.Handle("/api/visitors/count/realtime", api.Authorize(api.GetVisitorsRealtimeCountHandler)).Methods("GET")
|
|
|
|
r.Handle("/api/pageviews/count", api.Authorize(api.GetPageviewsCountHandler)).Methods("GET")
|
|
|
|
r.Handle("/api/pageviews/count/group/{period}", api.Authorize(api.GetPageviewsPeriodCountHandler)).Methods("GET")
|
|
|
|
r.Handle("/api/pageviews", api.Authorize(api.GetPageviewsHandler)).Methods("GET")
|
|
|
|
r.Handle("/api/languages", api.Authorize(api.GetLanguagesHandler)).Methods("GET")
|
|
|
|
r.Handle("/api/referrers", api.Authorize(api.GetReferrersHandler)).Methods("GET")
|
|
|
|
r.Handle("/api/screen-resolutions", api.Authorize(api.GetScreenResolutionsHandler)).Methods("GET")
|
|
|
|
r.Handle("/api/countries", api.Authorize(api.GetCountriesHandler)).Methods("GET")
|
|
|
|
r.Handle("/api/browsers", api.Authorize(api.GetBrowsersHandler)).Methods("GET")
|
2016-12-08 19:45:26 +00:00
|
|
|
|
2016-12-11 13:50:01 +00:00
|
|
|
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static/"))))
|
|
|
|
r.Path("/tracker.js").Handler(http.FileServer(http.Dir("./static/js/")))
|
|
|
|
r.Handle("/", http.FileServer(http.Dir("./views/")))
|
2016-12-08 19:45:26 +00:00
|
|
|
|
2016-12-11 13:50:01 +00:00
|
|
|
log.Print("API server is now listening on :8080")
|
|
|
|
http.ListenAndServe(":8080", handlers.LoggingHandler(os.Stdout, r))
|
2016-12-08 19:45:26 +00:00
|
|
|
}
|