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:
@@ -125,7 +125,7 @@ func main() {
|
|||||||
retentionScanner.Start()
|
retentionScanner.Start()
|
||||||
// Start HTTP server.
|
// Start HTTP server.
|
||||||
web.Initialize(conf, shutdownChan, mmanager, msgHub)
|
web.Initialize(conf, shutdownChan, mmanager, msgHub)
|
||||||
rest.SetupRoutes(web.Router)
|
rest.SetupRoutes(web.Router.PathPrefix("/api/").Subrouter())
|
||||||
webui.SetupRoutes(web.Router)
|
webui.SetupRoutes(web.Router)
|
||||||
go web.Start(rootCtx)
|
go web.Start(rootCtx)
|
||||||
// Start POP3 server.
|
// Start POP3 server.
|
||||||
|
|||||||
@@ -6,20 +6,20 @@ import "github.com/jhillyerd/inbucket/pkg/server/web"
|
|||||||
// SetupRoutes populates the routes for the REST interface
|
// SetupRoutes populates the routes for the REST interface
|
||||||
func SetupRoutes(r *mux.Router) {
|
func SetupRoutes(r *mux.Router) {
|
||||||
// API v1
|
// API v1
|
||||||
r.Path("/api/v1/mailbox/{name}").Handler(
|
r.Path("/v1/mailbox/{name}").Handler(
|
||||||
web.Handler(MailboxListV1)).Name("MailboxListV1").Methods("GET")
|
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")
|
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")
|
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")
|
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")
|
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")
|
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")
|
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")
|
web.Handler(MonitorMailboxMessagesV1)).Name("MonitorMailboxMessagesV1").Methods("GET")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ func setupWebServer(mm message.Manager) *bytes.Buffer {
|
|||||||
log.SetOutput(buf)
|
log.SetOutput(buf)
|
||||||
|
|
||||||
// Have to reset default mux to prevent duplicate routes
|
// Have to reset default mux to prevent duplicate routes
|
||||||
http.DefaultServeMux = http.NewServeMux()
|
|
||||||
cfg := &config.Root{
|
cfg := &config.Root{
|
||||||
Web: config.Web{
|
Web: config.Web{
|
||||||
UIDir: "../ui",
|
UIDir: "../ui",
|
||||||
@@ -51,7 +50,7 @@ func setupWebServer(mm message.Manager) *bytes.Buffer {
|
|||||||
}
|
}
|
||||||
shutdownChan := make(chan bool)
|
shutdownChan := make(chan bool)
|
||||||
web.Initialize(cfg, shutdownChan, mm, &msghub.Hub{})
|
web.Initialize(cfg, shutdownChan, mm, &msghub.Hub{})
|
||||||
SetupRoutes(web.Router)
|
SetupRoutes(web.Router.PathPrefix("/api/").Subrouter())
|
||||||
|
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user