fake-smtp/internal/route/mount.go

32 lines
808 B
Go

package route
import (
"forge.cadoles.com/Cadoles/fake-smtp/internal/config"
"github.com/go-chi/chi/v5"
"gitlab.com/wpetit/goweb/static"
)
func Mount(r *chi.Mux, config *config.Config) error {
r.Group(func(r chi.Router) {
r.Get("/", serveInboxPage)
r.Delete("/emails", handleClearInbox)
r.Get("/emails/{id}", serveEmailPage)
r.Get("/emails/{id}/html", serveEmailHTMLContent)
r.Get("/emails/{id}/attachments/{attachmendIndex}", serveEmailAttachment)
r.Delete("/emails/{id}", handleEmailDelete)
})
r.Route("/api", func(r chi.Router) {
r.Route("/v1", func(r chi.Router) {
r.Get("/emails", browseAPIV1Emails)
r.Get("/emails/{id}", serveAPIV1Email)
})
})
notFoundHandler := r.NotFoundHandler()
r.Get("/*", static.Dir(config.HTTP.PublicDir, "", notFoundHandler))
return nil
}