func main() {
	// sets the maximum number of CPUs that can be executing simultaneously
	runtime.GOMAXPROCS(runtime.NumCPU())

	// override defaults via env vars
	if os.Getenv("ES_HOST") != "" {
		esHost = os.Getenv("ES_HOST")
	}
	if os.Getenv("ES_PORT") != "" {
		esPort = os.Getenv("ES_PORT")
	}
	if os.Getenv("REDIS_HOST") != "" {
		redisHost = os.Getenv("REDIS_HOST")
	}
	if os.Getenv("REDIS_PORT") != "" {
		redisPort = os.Getenv("REDIS_PORT")
	}
	if os.Getenv("PUBLIC_DIR") != "" {
		publicDir = os.Getenv("PUBLIC_DIR")
	}

	// log endpoints
	log.Infof("Redis endpoint set to %s:%s", redisHost, redisPort)
	log.Infof("Elasticsearch endpoint set to %s:%s", esHost, esPort)

	// register available tiling types
	tile.Register("heatmap", elastic.NewHeatmapTile(esHost, esPort))
	tile.Register("topic_count", elastic.NewTopCountTile(esHost, esPort))
	// register available meta data types
	meta.Register("default", elastic.NewDefaultMeta(esHost, esPort))
	// register available store types
	store.Register("redis", redis.NewConnection(redisHost, redisPort))

	// create server
	app := api.New(publicDir)

	// catch kill signals for graceful shutdown
	graceful.AddSignal(syscall.SIGINT, syscall.SIGTERM)
	// start server
	log.Infof("Prism server listening on port %s", port)
	err := graceful.ListenAndServe(":"+port, app)
	if err != nil {
		log.Error(err)
	}
	// wait until server gracefully exits
	graceful.Wait()
}
// New returns a new Goji Mux handler to process HTTP requests.
func New(publicDir string) http.Handler {
	r := web.New()
	// mount logger middleware
	r.Use(middleware.Log)
	// mount gzip middleware
	r.Use(middleware.Gzip)
	// meta dispatching websocket handler
	log.Infof("Meta-Dispatch route: '%s'", dispatch.MetaRoute)
	r.Get(dispatch.MetaRoute, dispatch.MetaHandler)
	// tile dispatching websocket handler
	log.Infof("Tile-Dispatch route: '%s'", dispatch.TileRoute)
	r.Get(dispatch.TileRoute, dispatch.TileHandler)
	// tile request handler
	log.Infof("Tile route: '%s'", tile.Route)
	r.Post(tile.Route, tile.Handler)
	// metadata request handler
	log.Infof("Meta route: '%s'", meta.Route)
	r.Get(meta.Route, meta.Handler)
	// add greedy route last
	r.Get("/*", http.FileServer(http.Dir(publicDir)))
	return r
}