feat: wire the lighthouse realtime service

- Boot builds the realtime service and installs the user lookup
- the Centrifugo driver ships with the app; config keeps the null driver
- token and subscribe-proxy routes mount only with golem15.presentations,
  the token route behind presentations.realtime-owner
- jz.bm.realtime per-user throttle bucket and websockets:health
This commit is contained in:
Jakub Zych
2026-10-08 17:53:54 +02:00
parent 4b36eb940d
commit a740373b0e
3 changed files with 106 additions and 6 deletions

View File

@@ -8,6 +8,8 @@ import (
"git.golem15.com/golem15/summercms/modules/backpack"
"git.golem15.com/golem15/summercms/modules/bonfire"
"git.golem15.com/golem15/summercms/modules/lagoon"
"git.golem15.com/golem15/summercms/modules/lighthouse"
"git.golem15.com/golem15/summercms/modules/lighthouse/centrifugo"
"git.golem15.com/golem15/summercms/modules/pact"
"git.golem15.com/golem15/summercms/modules/party"
"git.golem15.com/jakub/sm-bm-plugin/console"
@@ -49,6 +51,9 @@ type Plugin struct {
// publicFS is the tree of the student app. Nil means the embedded
// public/ directory; tests plant their own.
publicFS fs.FS
// realtime is the app's lighthouse service, built at Boot. Nil when
// Boot did not run, as in tests that build routes on a bare plugin.
realtime *lighthouse.Service
}
func (p *Plugin) ID() string { return "jz.bm" }
@@ -63,10 +68,16 @@ func (p *Plugin) Register(app *backpack.App) error {
}
// Boot keeps the application, so route handlers and commands can reach its
// services, such as the database, when they run. The management API uses the
// shared user.api_token middleware owned by golem15.user.
// services, such as the database, when they run, and wires the realtime
// service. The management API uses the shared user.api_token middleware
// owned by golem15.user.
func (p *Plugin) Boot(app *backpack.App) error {
p.app = app
if app != nil {
if err := p.wireRealtime(app); err != nil {
return err
}
}
return nil
}
@@ -84,10 +95,11 @@ func (p *Plugin) AdminControllers() []pact.AdminController {
return generatedAdminControllers()
}
// Commands returns the generated commands plus bm:seed. API tokens are
// managed application-wide by golem15.user.
// Commands returns the generated commands, bm:seed and websockets:health.
// API tokens are managed application-wide by golem15.user.
func (p *Plugin) Commands() []bonfire.Command {
return append(generatedCommands(), console.SeedCommand(p.withDB))
cmds := append(generatedCommands(), console.SeedCommand(p.withDB))
return append(cmds, centrifugo.Commands(p.app)...)
}
// AdminFS is the admin YAML the controllers read.