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"
|
2017-06-08 21:26:58 +00:00
|
|
|
"github.com/animenotifier/arn"
|
2017-06-16 23:32:47 +00:00
|
|
|
"github.com/animenotifier/notify.moe/auth"
|
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"
|
2018-03-27 23:32:49 +00:00
|
|
|
"github.com/animenotifier/notify.moe/utils/routetests"
|
2016-11-09 11:32:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var app = aero.New()
|
|
|
|
|
|
|
|
func main() {
|
2017-06-22 14:08:34 +00:00
|
|
|
// Configure and start
|
|
|
|
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:")
|
2018-03-02 16:18:29 +00:00
|
|
|
|
2017-11-08 09:53:27 +00:00
|
|
|
// Security
|
|
|
|
configureHTTPS(app)
|
2017-07-14 21:50:34 +00:00
|
|
|
|
2017-10-02 00:09:05 +00:00
|
|
|
// Assets
|
|
|
|
configureAssets(app)
|
|
|
|
|
2017-11-08 09:53:27 +00:00
|
|
|
// Pages
|
|
|
|
pages.Configure(app)
|
|
|
|
|
2017-10-01 22:31:44 +00:00
|
|
|
// Rewrite
|
2017-10-02 00:09:05 +00:00
|
|
|
app.Rewrite(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(
|
|
|
|
middleware.Log(),
|
|
|
|
middleware.Session(),
|
2017-10-15 18:19:45 +00:00
|
|
|
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() {
|
2017-06-16 23:12:28 +00:00
|
|
|
app.Config.Domain = "beta.notify.moe"
|
2018-10-28 02:31:43 +00:00
|
|
|
app.Config.Title += " - Beta"
|
|
|
|
app.Config.Manifest.Name = app.Config.Title
|
2018-07-08 08:02:53 +00:00
|
|
|
|
|
|
|
// Test connectivity
|
|
|
|
app.OnStart(testConnectivity)
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2017-11-11 18:24:47 +00:00
|
|
|
// Do not use HTTP/2 push on service worker requests
|
|
|
|
app.AddPushCondition(func(ctx *aero.Context) bool {
|
2017-11-25 13:11:55 +00:00
|
|
|
return !strings.Contains(ctx.Request().Header().Get("Referer"), "/service-worker")
|
2017-11-11 18:24:47 +00:00
|
|
|
})
|
|
|
|
|
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() {
|
2017-10-01 22:31:44 +00:00
|
|
|
app.Test(route, examples)
|
|
|
|
}
|
|
|
|
|
2017-06-22 14:08:34 +00:00
|
|
|
return app
|
2016-11-09 11:32:19 +00:00
|
|
|
}
|