83 lines
1.5 KiB
Go
Raw Normal View History

2016-11-09 20:32:19 +09:00
package main
import (
2017-11-25 14:11:55 +01:00
"strings"
2016-11-09 22:11:49 +09:00
"github.com/aerogo/aero"
2017-10-28 03:53:12 +02:00
"github.com/aerogo/session-store-nano"
2017-06-08 23:26:58 +02:00
"github.com/animenotifier/arn"
2017-06-17 01:32:47 +02:00
"github.com/animenotifier/notify.moe/auth"
"github.com/animenotifier/notify.moe/components/css"
2017-06-17 01:12:28 +02:00
"github.com/animenotifier/notify.moe/middleware"
2017-11-07 16:49:56 +01:00
"github.com/animenotifier/notify.moe/pages"
2016-11-09 20:32:19 +09:00
)
var app = aero.New()
func main() {
2017-06-22 16:08:34 +02:00
// Configure and start
configure(app).Run()
}
func configure(app *aero.Application) *aero.Application {
2017-06-17 22:19:26 +02:00
// Sessions
2017-07-14 04:58:21 +02:00
app.Sessions.Duration = 3600 * 24 * 30 * 6
2017-10-31 12:12:21 +01:00
app.Sessions.Store = nanostore.New(arn.DB.Collection("Session"))
2017-06-08 23:26:58 +02:00
2017-11-08 10:53:27 +01:00
// CSS
app.SetStyle(css.Bundle())
// Security
configureHTTPS(app)
2017-07-14 23:50:34 +02:00
2017-10-02 02:09:05 +02:00
// Assets
configureAssets(app)
2017-11-08 10:53:27 +01:00
// Pages
pages.Configure(app)
2017-10-02 00:31:44 +02:00
// Rewrite
2017-10-02 02:09:05 +02:00
app.Rewrite(rewrite)
2017-10-02 00:31:44 +02:00
2017-06-17 01:12:28 +02:00
// Middleware
2017-10-14 17:18:32 +02:00
app.Use(
middleware.Log(),
middleware.Session(),
2017-10-15 20:19:45 +02:00
middleware.UserInfo(),
2017-10-14 17:18:32 +02:00
)
2017-06-12 21:11:20 +02:00
2017-06-17 01:12:28 +02:00
// API
2017-10-05 07:22:14 +02:00
arn.API.Install(app)
2017-06-12 21:11:20 +02:00
2017-06-17 01:12:28 +02:00
// Domain
2017-06-23 19:22:39 +02:00
if arn.IsDevelopment() {
2017-06-17 01:12:28 +02:00
app.Config.Domain = "beta.notify.moe"
}
2017-06-04 01:17:00 +02:00
2017-06-15 19:56:09 +02:00
// Authentication
2017-06-17 01:32:47 +02:00
auth.Install(app)
2017-06-15 19:56:09 +02:00
2017-11-02 04:08:45 +01:00
// Close the database node on shutdown
app.OnShutdown(arn.Node.Close)
2017-11-22 14:26:12 +01:00
// Check that this is the server
if !arn.Node.IsServer() {
panic("Another program is currently running as the database server")
}
2017-11-07 17:00:09 +01:00
// Prefetch all collections
2017-11-06 19:12:03 +01:00
arn.DB.Prefetch()
2017-11-02 04:08:45 +01:00
// Do not use HTTP/2 push on service worker requests
app.AddPushCondition(func(ctx *aero.Context) bool {
2017-11-25 14:11:55 +01:00
return !strings.Contains(ctx.Request().Header().Get("Referer"), "/service-worker")
})
2017-10-02 00:31:44 +02:00
// Specify test routes
for route, examples := range routeTests {
app.Test(route, examples)
}
2017-06-22 16:08:34 +02:00
return app
2016-11-09 20:32:19 +09:00
}