// New creates the API routes and returns a new http.Handler to serve them. func New(e *empire.Empire, authenticator auth.Authenticator) httpx.Handler { r := httpx.NewRouter() // Apps r.Handle("/apps", &GetApps{e}).Methods("GET") // hk apps r.Handle("/apps/{app}", &GetAppInfo{e}).Methods("GET") // hk info r.Handle("/apps/{app}", &DeleteApp{e}).Methods("DELETE") // hk destroy r.Handle("/apps/{app}", &PatchApp{e}).Methods("PATCH") // hk destroy r.Handle("/apps/{app}/deploys", &DeployApp{e}).Methods("POST") // Deploy an image to an app r.Handle("/apps", &PostApps{e}).Methods("POST") // hk create r.Handle("/organizations/apps", &PostApps{e}).Methods("POST") // hk create // Domains r.Handle("/apps/{app}/domains", &GetDomains{e}).Methods("GET") // hk domains r.Handle("/apps/{app}/domains", &PostDomains{e}).Methods("POST") // hk domain-add r.Handle("/apps/{app}/domains/{hostname}", &DeleteDomain{e}).Methods("DELETE") // hk domain-remove // Deploys r.Handle("/deploys", &PostDeploys{e}).Methods("POST") // Deploy an app // Releases r.Handle("/apps/{app}/releases", &GetReleases{e}).Methods("GET") // hk releases r.Handle("/apps/{app}/releases/{version}", &GetRelease{e}).Methods("GET") // hk release-info r.Handle("/apps/{app}/releases", &PostReleases{e}).Methods("POST") // hk rollback // Configs r.Handle("/apps/{app}/config-vars", &GetConfigs{e}).Methods("GET") // hk env, hk get r.Handle("/apps/{app}/config-vars", &PatchConfigs{e}).Methods("PATCH") // hk set, hk unset // Processes r.Handle("/apps/{app}/dynos", &GetProcesses{e}).Methods("GET") // hk dynos r.Handle("/apps/{app}/dynos", &PostProcess{e}).Methods("POST") // hk run r.Handle("/apps/{app}/dynos", &DeleteProcesses{e}).Methods("DELETE") // hk restart r.Handle("/apps/{app}/dynos/{ptype}.{pid}", &DeleteProcesses{e}).Methods("DELETE") // hk restart web.1 r.Handle("/apps/{app}/dynos/{pid}", &DeleteProcesses{e}).Methods("DELETE") // hk restart web // Formations r.Handle("/apps/{app}/formation", &PatchFormation{e}).Methods("PATCH") // hk scale // OAuth r.Handle("/oauth/authorizations", &PostAuthorizations{e}).Methods("POST") // SSL sslRemoved := errHandler(ErrSSLRemoved) r.Handle("/apps/{app}/ssl-endpoints", sslRemoved).Methods("GET") // hk ssl r.Handle("/apps/{app}/ssl-endpoints", sslRemoved).Methods("POST") // hk ssl-cert-add r.Handle("/apps/{app}/ssl-endpoints/{cert}", sslRemoved).Methods("PATCH") // hk ssl-cert-add, hk ssl-cert-rollback r.Handle("/apps/{app}/ssl-endpoints/{cert}", sslRemoved).Methods("DELETE") // hk ssl-destroy // Logs r.Handle("/apps/{app}/log-sessions", &PostLogs{e}).Methods("POST") // hk log errorHandler := func(err error, w http.ResponseWriter, r *http.Request) { Error(w, err, http.StatusInternalServerError) } api := Authenticate(r, authenticator) return middleware.HandleError(api, errorHandler) }
func NewHTTPHandler(r *Relay) http.Handler { m := httpx.NewRouter() m.Handle("POST", "/containers", &PostContainers{r}) var h httpx.Handler // Handle errors errorHandler := func(err error, w http.ResponseWriter, r *http.Request) { Error(w, err, http.StatusInternalServerError) } h = middleware.HandleError(m, errorHandler) // Recover from panics. h = middleware.Recover(h, reporter.NewLogReporter()) // Add a logger to the context. h = middleware.NewLogger(h, os.Stdout) // Add the request id to the context. h = middleware.ExtractRequestID(h) // Wrap the route in middleware to add a context.Context. return middleware.BackgroundContext(h) }