109 lines
2.5 KiB
Go
Raw Normal View History

2016-11-09 11:32:19 +00:00
package main
import (
2017-11-25 13:11:55 +00:00
"strings"
2016-11-09 13:11:49 +00:00
"github.com/aerogo/aero"
2018-12-07 07:20:10 +00:00
nanostore "github.com/aerogo/session-store-nano"
2019-06-01 04:55:49 +00:00
"github.com/akyoto/color"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
2019-05-23 06:02:13 +00:00
"github.com/animenotifier/notify.moe/assets"
2017-06-16 23:32:47 +00:00
"github.com/animenotifier/notify.moe/auth"
2019-05-11 07:03:37 +00:00
"github.com/animenotifier/notify.moe/graphql"
2017-06-16 23:12:28 +00:00
"github.com/animenotifier/notify.moe/middleware"
2017-11-07 15:49:56 +00:00
"github.com/animenotifier/notify.moe/pages"
2019-08-31 02:55:01 +00:00
"github.com/animenotifier/notify.moe/utils/htmlemail"
"github.com/animenotifier/notify.moe/utils/https"
2018-03-27 23:32:49 +00:00
"github.com/animenotifier/notify.moe/utils/routetests"
2016-11-09 11:32:19 +00:00
)
func main() {
2017-06-22 14:08:34 +00:00
// Configure and start
2019-05-10 08:36:39 +00:00
app := aero.New()
2017-06-22 14:08:34 +00:00
configure(app).Run()
}
func configure(app *aero.Application) *aero.Application {
2017-06-17 20:19:26 +00:00
// Sessions
2017-07-14 02:58:21 +00:00
app.Sessions.Duration = 3600 * 24 * 30 * 6
2017-10-31 11:12:21 +00:00
app.Sessions.Store = nanostore.New(arn.DB.Collection("Session"))
2017-06-08 21:26:58 +00:00
2018-03-02 16:18:29 +00:00
// Content security policy
app.ContentSecurityPolicy.Set("img-src", "https: data:")
2019-03-26 06:06:15 +00:00
app.ContentSecurityPolicy.Set("connect-src", "https: wss: data:")
2019-05-26 03:00:10 +00:00
app.ContentSecurityPolicy.Set("font-src", "https: data:")
2018-03-02 16:18:29 +00:00
2017-11-08 09:53:27 +00:00
// Security
2019-08-31 02:55:01 +00:00
https.Configure(app)
2017-07-14 21:50:34 +00:00
2017-10-02 00:09:05 +00:00
// Assets
2019-05-23 06:02:13 +00:00
assets.Configure(app)
2017-10-02 00:09:05 +00:00
2017-11-08 09:53:27 +00:00
// Pages
pages.Configure(app)
2017-10-01 22:31:44 +00:00
// Rewrite
2019-08-31 02:55:01 +00:00
app.Rewrite(pages.Rewrite)
2017-10-01 22:31:44 +00:00
2017-06-16 23:12:28 +00:00
// Middleware
2017-10-14 15:18:32 +00:00
app.Use(
2019-06-03 05:53:04 +00:00
middleware.Recover,
middleware.HTTPSRedirect,
2019-06-01 04:55:49 +00:00
middleware.OpenGraph,
middleware.Log,
middleware.Session,
middleware.UserInfo,
2017-10-14 15:18:32 +00:00
)
2017-06-12 19:11:20 +00:00
2017-06-16 23:12:28 +00:00
// API
2017-10-05 05:22:14 +00:00
arn.API.Install(app)
2017-06-12 19:11:20 +00:00
2018-07-08 08:02:53 +00:00
// Development server configuration
2017-06-23 17:22:39 +00:00
if arn.IsDevelopment() {
2019-06-01 04:55:49 +00:00
assets.Domain = "beta.notify.moe"
assets.Manifest.Name += " - Beta"
2017-06-16 23:12:28 +00:00
}
2017-06-03 23:17:00 +00:00
2017-06-15 17:56:09 +00:00
// Authentication
2017-06-16 23:32:47 +00:00
auth.Install(app)
2017-06-15 17:56:09 +00:00
2019-05-10 08:36:39 +00:00
// GraphQL
2019-05-11 07:03:37 +00:00
graphql.Install(app)
2019-05-10 08:36:39 +00:00
2017-11-02 03:08:45 +00:00
// Close the database node on shutdown
2018-05-29 06:35:18 +00:00
app.OnEnd(arn.Node.Close)
2017-11-02 03:08:45 +00:00
2019-06-03 05:53:04 +00:00
// Don't push when an underscore URL has been requested
app.AddPushCondition(func(ctx aero.Context) bool {
return !strings.HasPrefix(ctx.Path(), "/_")
})
2019-06-01 04:55:49 +00:00
// Show errors in the console
app.OnError(func(ctx aero.Context, err error) {
color.Red(err.Error())
})
2019-08-16 05:27:45 +00:00
// Emails
2019-08-31 02:55:01 +00:00
arn.HTMLEmailRenderer = &htmlemail.Renderer{}
2019-08-16 05:27:45 +00:00
2017-11-22 13:26:12 +00:00
// Check that this is the server
2018-03-21 19:22:57 +00:00
if !arn.Node.IsServer() && !arn.IsTest() {
2017-11-22 13:26:12 +00:00
panic("Another program is currently running as the database server")
}
2017-11-07 16:00:09 +00:00
// Prefetch all collections
2017-11-06 18:12:03 +00:00
arn.DB.Prefetch()
2017-11-02 03:08:45 +00:00
// Do not use HTTP/2 push on service worker requests
2019-06-01 04:55:49 +00:00
app.AddPushCondition(func(ctx aero.Context) bool {
return !strings.Contains(ctx.Request().Header("Referer"), "/service-worker")
})
2017-10-01 22:31:44 +00:00
// Specify test routes
2018-03-27 23:32:49 +00:00
for route, examples := range routetests.All() {
2019-06-01 04:55:49 +00:00
app.Test(route, examples...)
2017-10-01 22:31:44 +00:00
}
2017-06-22 14:08:34 +00:00
return app
2016-11-09 11:32:19 +00:00
}