This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
main.go
85 lines (65 loc) · 1.79 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"strings"
"github.com/aerogo/aero"
nanostore "github.com/aerogo/session-store-nano"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/auth"
"github.com/animenotifier/notify.moe/middleware"
"github.com/animenotifier/notify.moe/pages"
"github.com/animenotifier/notify.moe/utils/routetests"
)
var app = aero.New()
func main() {
// Configure and start
configure(app).Run()
}
func configure(app *aero.Application) *aero.Application {
// Sessions
app.Sessions.Duration = 3600 * 24 * 30 * 6
app.Sessions.Store = nanostore.New(arn.DB.Collection("Session"))
// Content security policy
app.ContentSecurityPolicy.Set("img-src", "https: data:")
app.ContentSecurityPolicy.Set("connect-src", "https: wss: data:")
// Security
configureHTTPS(app)
// Assets
configureAssets(app)
// Pages
pages.Configure(app)
// Rewrite
app.Rewrite(rewrite)
// Middleware
app.Use(
middleware.Log(),
middleware.Session(),
middleware.UserInfo(),
)
// API
arn.API.Install(app)
// Development server configuration
if arn.IsDevelopment() {
app.Config.Domain = "beta.notify.moe"
app.Config.Title += " - Beta"
app.Config.Manifest.Name = app.Config.Title
}
// Authentication
auth.Install(app)
// Close the database node on shutdown
app.OnEnd(arn.Node.Close)
// Check that this is the server
if !arn.Node.IsServer() && !arn.IsTest() {
panic("Another program is currently running as the database server")
}
// Prefetch all collections
arn.DB.Prefetch()
// Do not use HTTP/2 push on service worker requests
app.AddPushCondition(func(ctx *aero.Context) bool {
return !strings.Contains(ctx.Request().Header().Get("Referer"), "/service-worker")
})
// Specify test routes
for route, examples := range routetests.All() {
app.Test(route, examples)
}
return app
}