From cf83ed478c93719404f3b7fffcc90daae1e1eb90 Mon Sep 17 00:00:00 2001 From: oers Date: Sun, 6 Mar 2016 11:57:39 +0100 Subject: [PATCH] Fix for mailhog/Mailhog#25. Provide a webpath to serve content under --- api/v1.go | 30 +++++++++++++++--------------- api/v2.go | 24 ++++++++++++------------ config/config.go | 2 ++ 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/api/v1.go b/api/v1.go index a0fc1fe..f026e29 100644 --- a/api/v1.go +++ b/api/v1.go @@ -33,32 +33,32 @@ var stream *goose.EventStream type ReleaseConfig config.OutgoingSMTP func CreateAPIv1(conf *config.Config, r *pat.Router) *APIv1 { - log.Println("Creating API v1") + log.Println("Creating API v1 with WebPath: " + conf.WebPath) apiv1 := &APIv1{ config: conf, } stream = goose.NewEventStream() - r.Path("/api/v1/messages").Methods("GET").HandlerFunc(apiv1.messages) - r.Path("/api/v1/messages").Methods("DELETE").HandlerFunc(apiv1.delete_all) - r.Path("/api/v1/messages").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions) + r.Path(conf.WebPath + "/api/v1/messages").Methods("GET").HandlerFunc(apiv1.messages) + r.Path(conf.WebPath + "/api/v1/messages").Methods("DELETE").HandlerFunc(apiv1.delete_all) + r.Path(conf.WebPath + "/api/v1/messages").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions) - r.Path("/api/v1/messages/{id}").Methods("GET").HandlerFunc(apiv1.message) - r.Path("/api/v1/messages/{id}").Methods("DELETE").HandlerFunc(apiv1.delete_one) - r.Path("/api/v1/messages/{id}").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions) + r.Path(conf.WebPath + "/api/v1/messages/{id}").Methods("GET").HandlerFunc(apiv1.message) + r.Path(conf.WebPath + "/api/v1/messages/{id}").Methods("DELETE").HandlerFunc(apiv1.delete_one) + r.Path(conf.WebPath + "/api/v1/messages/{id}").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions) - r.Path("/api/v1/messages/{id}/download").Methods("GET").HandlerFunc(apiv1.download) - r.Path("/api/v1/messages/{id}/download").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions) + r.Path(conf.WebPath + "/api/v1/messages/{id}/download").Methods("GET").HandlerFunc(apiv1.download) + r.Path(conf.WebPath + "/api/v1/messages/{id}/download").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions) - r.Path("/api/v1/messages/{id}/mime/part/{part}/download").Methods("GET").HandlerFunc(apiv1.download_part) - r.Path("/api/v1/messages/{id}/mime/part/{part}/download").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions) + r.Path(conf.WebPath + "/api/v1/messages/{id}/mime/part/{part}/download").Methods("GET").HandlerFunc(apiv1.download_part) + r.Path(conf.WebPath + "/api/v1/messages/{id}/mime/part/{part}/download").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions) - r.Path("/api/v1/messages/{id}/release").Methods("POST").HandlerFunc(apiv1.release_one) - r.Path("/api/v1/messages/{id}/release").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions) + r.Path(conf.WebPath + "/api/v1/messages/{id}/release").Methods("POST").HandlerFunc(apiv1.release_one) + r.Path(conf.WebPath + "/api/v1/messages/{id}/release").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions) - r.Path("/api/v1/events").Methods("GET").HandlerFunc(apiv1.eventstream) - r.Path("/api/v1/events").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions) + r.Path(conf.WebPath + "/api/v1/events").Methods("GET").HandlerFunc(apiv1.eventstream) + r.Path(conf.WebPath + "/api/v1/events").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions) go func() { for { diff --git a/api/v2.go b/api/v2.go index 541a474..7f8f9a6 100644 --- a/api/v2.go +++ b/api/v2.go @@ -21,25 +21,25 @@ type APIv2 struct { } func CreateAPIv2(conf *config.Config, r *pat.Router) *APIv2 { - log.Println("Creating API v2") + log.Println("Creating API v2 with WebPath: " + conf.WebPath) apiv2 := &APIv2{ config: conf, } - r.Path("/api/v2/messages").Methods("GET").HandlerFunc(apiv2.messages) - r.Path("/api/v2/messages").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions) + r.Path(conf.WebPath + "/api/v2/messages").Methods("GET").HandlerFunc(apiv2.messages) + r.Path(conf.WebPath + "/api/v2/messages").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions) - r.Path("/api/v2/search").Methods("GET").HandlerFunc(apiv2.search) - r.Path("/api/v2/search").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions) + r.Path(conf.WebPath + "/api/v2/search").Methods("GET").HandlerFunc(apiv2.search) + r.Path(conf.WebPath + "/api/v2/search").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions) - r.Path("/api/v2/jim").Methods("GET").HandlerFunc(apiv2.jim) - r.Path("/api/v2/jim").Methods("POST").HandlerFunc(apiv2.createJim) - r.Path("/api/v2/jim").Methods("PUT").HandlerFunc(apiv2.updateJim) - r.Path("/api/v2/jim").Methods("DELETE").HandlerFunc(apiv2.deleteJim) - r.Path("/api/v2/jim").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions) + r.Path(conf.WebPath + "/api/v2/jim").Methods("GET").HandlerFunc(apiv2.jim) + r.Path(conf.WebPath + "/api/v2/jim").Methods("POST").HandlerFunc(apiv2.createJim) + r.Path(conf.WebPath + "/api/v2/jim").Methods("PUT").HandlerFunc(apiv2.updateJim) + r.Path(conf.WebPath + "/api/v2/jim").Methods("DELETE").HandlerFunc(apiv2.deleteJim) + r.Path(conf.WebPath + "/api/v2/jim").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions) - r.Path("/api/v2/outgoing-smtp").Methods("GET").HandlerFunc(apiv2.listOutgoingSMTP) - r.Path("/api/v2/outgoing-smtp").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions) + r.Path(conf.WebPath + "/api/v2/outgoing-smtp").Methods("GET").HandlerFunc(apiv2.listOutgoingSMTP) + r.Path(conf.WebPath + "/api/v2/outgoing-smtp").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions) return apiv2 } diff --git a/config/config.go b/config/config.go index 336f051..5e72b65 100644 --- a/config/config.go +++ b/config/config.go @@ -22,6 +22,7 @@ func DefaultConfig() *Config { MongoColl: "messages", StorageType: "memory", CORSOrigin: "", + WebPath: "", MessageChan: make(chan *data.Message), OutgoingSMTP: make(map[string]*OutgoingSMTP), } @@ -43,6 +44,7 @@ type Config struct { Monkey monkey.ChaosMonkey OutgoingSMTPFile string OutgoingSMTP map[string]*OutgoingSMTP + WebPath string } type OutgoingSMTP struct {