mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 09:37:02 +00:00
rest: Use a subrouter for /api/ paths
This commit is contained in:
@@ -6,20 +6,20 @@ import "github.com/jhillyerd/inbucket/pkg/server/web"
|
||||
// SetupRoutes populates the routes for the REST interface
|
||||
func SetupRoutes(r *mux.Router) {
|
||||
// API v1
|
||||
r.Path("/api/v1/mailbox/{name}").Handler(
|
||||
r.Path("/v1/mailbox/{name}").Handler(
|
||||
web.Handler(MailboxListV1)).Name("MailboxListV1").Methods("GET")
|
||||
r.Path("/api/v1/mailbox/{name}").Handler(
|
||||
r.Path("/v1/mailbox/{name}").Handler(
|
||||
web.Handler(MailboxPurgeV1)).Name("MailboxPurgeV1").Methods("DELETE")
|
||||
r.Path("/api/v1/mailbox/{name}/{id}").Handler(
|
||||
r.Path("/v1/mailbox/{name}/{id}").Handler(
|
||||
web.Handler(MailboxShowV1)).Name("MailboxShowV1").Methods("GET")
|
||||
r.Path("/api/v1/mailbox/{name}/{id}").Handler(
|
||||
r.Path("/v1/mailbox/{name}/{id}").Handler(
|
||||
web.Handler(MailboxMarkSeenV1)).Name("MailboxMarkSeenV1").Methods("PATCH")
|
||||
r.Path("/api/v1/mailbox/{name}/{id}").Handler(
|
||||
r.Path("/v1/mailbox/{name}/{id}").Handler(
|
||||
web.Handler(MailboxDeleteV1)).Name("MailboxDeleteV1").Methods("DELETE")
|
||||
r.Path("/api/v1/mailbox/{name}/{id}/source").Handler(
|
||||
r.Path("/v1/mailbox/{name}/{id}/source").Handler(
|
||||
web.Handler(MailboxSourceV1)).Name("MailboxSourceV1").Methods("GET")
|
||||
r.Path("/api/v1/monitor/messages").Handler(
|
||||
r.Path("/v1/monitor/messages").Handler(
|
||||
web.Handler(MonitorAllMessagesV1)).Name("MonitorAllMessagesV1").Methods("GET")
|
||||
r.Path("/api/v1/monitor/messages/{name}").Handler(
|
||||
r.Path("/v1/monitor/messages/{name}").Handler(
|
||||
web.Handler(MonitorMailboxMessagesV1)).Name("MonitorMailboxMessagesV1").Methods("GET")
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@ func setupWebServer(mm message.Manager) *bytes.Buffer {
|
||||
log.SetOutput(buf)
|
||||
|
||||
// Have to reset default mux to prevent duplicate routes
|
||||
http.DefaultServeMux = http.NewServeMux()
|
||||
cfg := &config.Root{
|
||||
Web: config.Web{
|
||||
UIDir: "../ui",
|
||||
@@ -51,7 +50,7 @@ func setupWebServer(mm message.Manager) *bytes.Buffer {
|
||||
}
|
||||
shutdownChan := make(chan bool)
|
||||
web.Initialize(cfg, shutdownChan, mm, &msghub.Hub{})
|
||||
SetupRoutes(web.Router)
|
||||
SetupRoutes(web.Router.PathPrefix("/api/").Subrouter())
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user