diff --git a/email.go b/email.go deleted file mode 100644 index f5630855..00000000 --- a/email.go +++ /dev/null @@ -1,14 +0,0 @@ -package main - -import ( - "github.com/animenotifier/notify.moe/arn" - "github.com/animenotifier/notify.moe/components" -) - -// HTMLEmailRenderer uses pixy templates to render the HTML for our emails. -type HTMLEmailRenderer struct{} - -// Notification renders a notification email. -func (writer *HTMLEmailRenderer) Notification(notification *arn.Notification) string { - return components.NotificationEmail(notification) -} diff --git a/main.go b/main.go index 40054fc7..4ce1b1ce 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,8 @@ import ( "github.com/animenotifier/notify.moe/graphql" "github.com/animenotifier/notify.moe/middleware" "github.com/animenotifier/notify.moe/pages" + "github.com/animenotifier/notify.moe/utils/htmlemail" + "github.com/animenotifier/notify.moe/utils/https" "github.com/animenotifier/notify.moe/utils/routetests" ) @@ -32,7 +34,7 @@ func configure(app *aero.Application) *aero.Application { app.ContentSecurityPolicy.Set("font-src", "https: data:") // Security - configureHTTPS(app) + https.Configure(app) // Assets assets.Configure(app) @@ -41,7 +43,7 @@ func configure(app *aero.Application) *aero.Application { pages.Configure(app) // Rewrite - app.Rewrite(rewrite) + app.Rewrite(pages.Rewrite) // Middleware app.Use( @@ -82,7 +84,7 @@ func configure(app *aero.Application) *aero.Application { }) // Emails - arn.HTMLEmailRenderer = &HTMLEmailRenderer{} + arn.HTMLEmailRenderer = &htmlemail.Renderer{} // Check that this is the server if !arn.Node.IsServer() && !arn.IsTest() { diff --git a/pages/index.go b/pages/index.go index 6973edf8..94af19f8 100644 --- a/pages/index.go +++ b/pages/index.go @@ -1,6 +1,8 @@ package pages import ( + "strings" + "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/pages/index/amvroutes" "github.com/animenotifier/notify.moe/pages/index/animeroutes" @@ -48,3 +50,29 @@ func Configure(app *aero.Application) { // app.Get("/database", database.Get) // app.Get("/api/select/:data-type/where/:field/is/:field-value", database.Select) } + +// Rewrite will rewrite the path before routing happens. +func Rewrite(ctx aero.RewriteContext) { + requestURI := ctx.Path() + + // User profiles + if strings.HasPrefix(requestURI, "/+") { + newURI := "/user/" + userName := requestURI[2:] + ctx.SetPath(newURI + userName) + return + } + + if strings.HasPrefix(requestURI, "/_/+") { + newURI := "/_/user/" + userName := requestURI[4:] + ctx.SetPath(newURI + userName) + return + } + + // Analytics + if requestURI == "/dark-flame-master" { + ctx.SetPath("/api/new/analytics") + return + } +} diff --git a/rewrite.go b/rewrite.go deleted file mode 100644 index e5356bfb..00000000 --- a/rewrite.go +++ /dev/null @@ -1,33 +0,0 @@ -package main - -import ( - "strings" - - "github.com/aerogo/aero" -) - -// rewrite will rewrite certain routes -func rewrite(ctx aero.RewriteContext) { - requestURI := ctx.Path() - - // User profiles - if strings.HasPrefix(requestURI, "/+") { - newURI := "/user/" - userName := requestURI[2:] - ctx.SetPath(newURI + userName) - return - } - - if strings.HasPrefix(requestURI, "/_/+") { - newURI := "/_/user/" - userName := requestURI[4:] - ctx.SetPath(newURI + userName) - return - } - - // Analytics - if requestURI == "/dark-flame-master" { - ctx.SetPath("/api/new/analytics") - return - } -} diff --git a/utils/htmlemail/Renderer.go b/utils/htmlemail/Renderer.go new file mode 100644 index 00000000..7aa8f332 --- /dev/null +++ b/utils/htmlemail/Renderer.go @@ -0,0 +1,14 @@ +package htmlemail + +import ( + "github.com/animenotifier/notify.moe/arn" + "github.com/animenotifier/notify.moe/components" +) + +// Renderer uses pixy templates to render the HTML for our emails. +type Renderer struct{} + +// Notification renders a notification email. +func (writer *Renderer) Notification(notification *arn.Notification) string { + return components.NotificationEmail(notification) +} diff --git a/security.go b/utils/https/Configure.go similarity index 93% rename from security.go rename to utils/https/Configure.go index 1d776090..202cba0e 100644 --- a/security.go +++ b/utils/https/Configure.go @@ -1,4 +1,4 @@ -package main +package https import ( "os" @@ -9,7 +9,8 @@ import ( "github.com/animenotifier/notify.moe/arn" ) -func configureHTTPS(app *aero.Application) { +// Configure loads the certificates. +func Configure(app *aero.Application) { fullCertPath := path.Join(arn.Root, "security", "fullchain.pem") fullKeyPath := path.Join(arn.Root, "security", "privkey.pem")