summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-01-03 10:50:59 +0000
committerLibravatar GitHub <noreply@github.com>2023-01-03 11:50:59 +0100
commit71dfea7e47eef3d89b0c4919d71a6ad58e35912d (patch)
treee2585e1b50865fff4d57f8270a4a388bcf61f8c7 /cmd
parent[docs] Add troubleshooting section for Apache (#1291) (diff)
downloadgotosocial-71dfea7e47eef3d89b0c4919d71a6ad58e35912d.tar.xz
[chore] shuffle middleware to split rate limitting into client/s2s/fileserver, share gzip middleware globally (#1290)
Signed-off-by: kim <grufwub@gmail.com> Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gotosocial/action/server/server.go25
1 files changed, 16 insertions, 9 deletions
diff --git a/cmd/gotosocial/action/server/server.go b/cmd/gotosocial/action/server/server.go
index 7e07b76ab..7a4b315da 100644
--- a/cmd/gotosocial/action/server/server.go
+++ b/cmd/gotosocial/action/server/server.go
@@ -183,14 +183,21 @@ var Start action.GTSAction = func(ctx context.Context) error {
webModule = web.New(processor) // web pages + user profiles + settings panels etc
)
+ // create required middleware
+ limit := config.GetAdvancedRateLimitRequests()
+ gzip := middleware.Gzip() // all except fileserver
+ clLimit := middleware.RateLimit(limit) // client api
+ s2sLimit := middleware.RateLimit(limit) // server-to-server (AP)
+ fsLimit := middleware.RateLimit(limit) // fileserver / web templates
+
// these should be routed in order
- authModule.Route(router)
- clientModule.Route(router)
- fileserverModule.Route(router)
- wellKnownModule.Route(router)
- nodeInfoModule.Route(router)
- activityPubModule.Route(router)
- webModule.Route(router)
+ authModule.Route(router, clLimit, gzip)
+ clientModule.Route(router, clLimit, gzip)
+ fileserverModule.Route(router, fsLimit)
+ wellKnownModule.Route(router, gzip, s2sLimit)
+ nodeInfoModule.Route(router, s2sLimit, gzip)
+ activityPubModule.Route(router, s2sLimit, gzip)
+ webModule.Route(router, fsLimit, gzip)
gts, err := gotosocial.NewServer(dbService, router, federator, mediaManager)
if err != nil {
@@ -208,8 +215,8 @@ var Start action.GTSAction = func(ctx context.Context) error {
// catch shutdown signals from the operating system
sigs := make(chan os.Signal, 1)
- signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)
- sig := <-sigs
+ signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
+ sig := <-sigs // block until signal received
log.Infof("received signal %s, shutting down", sig)
// close down all running services in order