Skip to content

Commit d4cf86a

Browse files
authored
feat: hot-reloading + file serving (#67)
* feat: ui handler * feat: hot reloading * chore: relative paths for the index * chore: cleanup custom ServeFile
1 parent 44946f6 commit d4cf86a

15 files changed

Lines changed: 1305 additions & 921 deletions

File tree

cmd/serve.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ to interact and monitor the Scroll Application`,
127127
snapshotService := snapshotServices.NewSnapshotService()
128128
coldStarter := services.NewColdStarter(portService, queueManager, snapshotService, scrollService.GetDir())
129129

130+
uiService := services.NewUiService(scrollService)
131+
uiDevService := services.NewUiDevService()
132+
130133
scrollHandler := handler.NewScrollHandler(scrollService, pluginManager, processLauncher, queueManager, processManager)
131134
processHandler := handler.NewProcessHandler(processManager)
132135
scrollLogHandler := handler.NewScrollLogHandler(scrollService, logManager, processManager)
@@ -135,6 +138,8 @@ to interact and monitor the Scroll Application`,
135138
portHandler := handler.NewPortHandler(portService)
136139
healthHandler := handler.NewHealthHandler(portService, maxStartupHealthCheckTimeout, snapshotService)
137140
coldstarterHandler := handler.NewColdstarterHandler(coldStarter)
141+
uiHandler := handler.NewUiHandler(uiService)
142+
uiDevHandler := handler.NewUiDevHandler(uiDevService, scrollService)
138143

139144
var annotationHandler *handler.AnnotationHandler = nil
140145

@@ -147,7 +152,7 @@ to interact and monitor the Scroll Application`,
147152
signalHandler := signals.NewSignalHandler(ctx, queueManager, processManager, nil, shutdownWait)
148153
daemonHander := handler.NewDaemonHandler(signalHandler)
149154

150-
s := web.NewServer(jwksUrl, scrollHandler, scrollLogHandler, scrollMetricHandler, annotationHandler, processHandler, queueHandler, websocketHandler, portHandler, healthHandler, coldstarterHandler, daemonHander, authorizer, cwd)
155+
s := web.NewServer(jwksUrl, scrollHandler, scrollLogHandler, scrollMetricHandler, annotationHandler, processHandler, queueHandler, websocketHandler, portHandler, healthHandler, coldstarterHandler, daemonHander, authorizer, uiHandler, uiDevHandler, cwd, scrollService.GetDir())
151156

152157
a := s.Initialize()
153158

cmd/server/web/server.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/gofiber/fiber/v2/middleware/cors"
1111
jwtware "github.com/gofiber/jwt/v3"
1212
"github.com/highcard-dev/daemon/cmd/server/web/middlewares"
13+
1314
constants "github.com/highcard-dev/daemon/internal"
1415
"github.com/highcard-dev/daemon/internal/core/ports"
1516
"github.com/highcard-dev/daemon/internal/utils/logger"
@@ -36,8 +37,11 @@ type Server struct {
3637
portHandler ports.PortHandlerInterface
3738
healthHandler ports.HealthHandlerInterface
3839
coldstarterHandler ports.ColdstarterHandlerInterface
39-
daemonHander ports.SignalHandlerInterface
40+
daemonHandler ports.SignalHandlerInterface
41+
uiHandler ports.UiHandlerInterface
42+
uiDevHandler ports.UiDevHandlerInterface
4043
webdavPath string
44+
scrollPath string
4145
}
4246

4347
func NewServer(
@@ -52,9 +56,12 @@ func NewServer(
5256
portHandler ports.PortHandlerInterface,
5357
healthHandler ports.HealthHandlerInterface,
5458
coldstarterHandler ports.ColdstarterHandlerInterface,
55-
daemonHander ports.SignalHandlerInterface,
59+
daemonHandler ports.SignalHandlerInterface,
5660
authorizerService ports.AuthorizerServiceInterface,
61+
uiHandler ports.UiHandlerInterface,
62+
uiDevHandler ports.UiDevHandlerInterface,
5763
webdavPath string,
64+
scrollPath string,
5865
) *Server {
5966
server := &Server{
6067
corsMiddleware: cors.New(cors.Config{
@@ -76,7 +83,10 @@ func NewServer(
7683
healthHandler: healthHandler,
7784
coldstarterHandler: coldstarterHandler,
7885
webdavPath: webdavPath,
79-
daemonHander: daemonHander,
86+
scrollPath: scrollPath,
87+
daemonHandler: daemonHandler,
88+
uiHandler: uiHandler,
89+
uiDevHandler: uiDevHandler,
8090
}
8191

8292
if jwlsUrl != "" {
@@ -121,9 +131,13 @@ func (s *Server) SetAPI(app *fiber.App) *fiber.App {
121131
apiRoutes := v1.Group("/")
122132
webdavRoutes := app.Group("/webdav")
123133

134+
privateUiRoutes := app.Use(s.corsMiddleware)
135+
publicUiRoutes := app.Use(s.corsMiddleware)
136+
124137
if s.jwtMiddleware != nil {
125138
apiRoutes.Use(s.jwtMiddleware, s.injectUserMiddleware)
126139
webdavRoutes.Use(s.jwtMiddleware, s.injectUserMiddleware)
140+
privateUiRoutes.Use(s.jwtMiddleware, s.injectUserMiddleware)
127141
}
128142

129143
wsRoutes.Use(s.tokenAuthenticationMiddleware)
@@ -157,7 +171,12 @@ func (s *Server) SetAPI(app *fiber.App) *fiber.App {
157171

158172
apiRoutes.Get("/health", s.healthHandler.Health).Name("health-authenticated")
159173

160-
apiRoutes.Post("/daemon/stop", s.daemonHander.Stop).Name("daemon.stop")
174+
apiRoutes.Post("/daemon/stop", s.daemonHandler.Stop).Name("daemon.stop")
175+
176+
//UI Dev Group
177+
apiRoutes.Post("/dev/enable", s.uiDevHandler.Enable).Name("dev.enable")
178+
apiRoutes.Post("/dev/disable", s.uiDevHandler.Disable).Name("dev.disable")
179+
apiRoutes.Get("/dev/status", s.uiDevHandler.Status).Name("dev.status")
161180

162181
// Create the WebDAV handler
163182
webdavHandler := &webdav.Handler{
@@ -169,9 +188,16 @@ func (s *Server) SetAPI(app *fiber.App) *fiber.App {
169188
webdavRoutes.Use("*", adaptor.HTTPHandler(webdavHandler))
170189

171190
wsRoutes.Get("/serve/:console", websocket.New(s.websocketHandler.HandleProcess)).Name("ws.serve")
191+
wsRoutes.Get("/dev/notify", websocket.New(s.uiDevHandler.NotifyChange)).Name("ws.dev.notify")
172192

173193
apiRoutes.Get("/ports", s.portHandler.GetPorts).Name("ports.list")
174194

195+
publicUiRoutes.Get("/public/index", s.uiHandler.PublicIndex).Name("ui.public_index")
196+
publicUiRoutes.Static("/public", s.scrollPath+"/public").Name("ui.public")
197+
198+
privateUiRoutes.Get("/private/index", s.uiHandler.PrivateIndex).Name("ui.private_index")
199+
privateUiRoutes.Static("/private", s.scrollPath+"/private").Name("ui.private")
200+
175201
if s.annotationHandler != nil {
176202
app.Get("/annotations", s.annotationHandler.Annotations).Name("annotations.list")
177203
}

go.mod

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module github.com/highcard-dev/daemon
22

3-
go 1.23.0
3+
go 1.24.0
4+
5+
toolchain go1.24.7
46

57
require (
68
github.com/Masterminds/semver/v3 v3.2.1
@@ -24,12 +26,12 @@ require (
2426
github.com/KyleBanks/depth v1.2.1 // indirect
2527
github.com/Masterminds/goutils v1.1.1 // indirect
2628
github.com/Masterminds/semver v1.5.0 // indirect
27-
github.com/andybalholm/brotli v1.1.0 // indirect
29+
github.com/andybalholm/brotli v1.2.0 // indirect
2830
github.com/beorn7/perks v1.0.1 // indirect
2931
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3032
github.com/fasthttp/websocket v1.5.8 // indirect
3133
github.com/fatih/color v1.15.0 // indirect
32-
github.com/fsnotify/fsnotify v1.7.0 // indirect
34+
github.com/fsnotify/fsnotify v1.7.0
3335
github.com/go-ole/go-ole v1.2.6 // indirect
3436
github.com/go-openapi/jsonpointer v0.19.6 // indirect
3537
github.com/go-openapi/jsonreference v0.20.2 // indirect
@@ -45,10 +47,10 @@ require (
4547
github.com/inconshreveable/mousetrap v1.1.0 // indirect
4648
github.com/joho/godotenv v1.5.1
4749
github.com/josharian/intern v1.0.0 // indirect
48-
github.com/klauspost/compress v1.17.11 // indirect
50+
github.com/klauspost/compress v1.18.0 // indirect
4951
github.com/magiconair/properties v1.8.7 // indirect
5052
github.com/mailru/easyjson v0.7.7 // indirect
51-
github.com/mattn/go-colorable v0.1.13
53+
github.com/mattn/go-colorable v0.1.14
5254
github.com/mattn/go-isatty v0.0.20 // indirect
5355
github.com/mattn/go-runewidth v0.0.16 // indirect
5456
github.com/mitchellh/copystructure v1.2.0 // indirect
@@ -69,47 +71,28 @@ require (
6971
github.com/tklauser/go-sysconf v0.3.12 // indirect
7072
github.com/tklauser/numcpus v0.6.1 // indirect
7173
github.com/valyala/bytebufferpool v1.0.0 // indirect
72-
github.com/valyala/fasthttp v1.52.0 // indirect
73-
github.com/valyala/tcplisten v1.0.0 // indirect
74+
github.com/valyala/fasthttp v1.65.0 // indirect
7475
github.com/yusufpapurcu/wmi v1.2.3 // indirect
7576
go.uber.org/multierr v1.11.0 // indirect
76-
golang.org/x/crypto v0.31.0 // indirect
77-
golang.org/x/net v0.33.0
78-
golang.org/x/sync v0.10.0 // indirect
79-
golang.org/x/sys v0.28.0 // indirect
80-
golang.org/x/text v0.21.0 // indirect
81-
golang.org/x/tools v0.28.0 // indirect
77+
golang.org/x/crypto v0.42.0 // indirect
78+
golang.org/x/net v0.44.0
79+
golang.org/x/sync v0.17.0 // indirect
80+
golang.org/x/sys v0.36.0 // indirect
81+
golang.org/x/text v0.29.0 // indirect
82+
golang.org/x/tools v0.36.0 // indirect
8283
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
8384
google.golang.org/grpc v1.65.0
8485
google.golang.org/protobuf v1.34.2
8586
gopkg.in/ini.v1 v1.67.0 // indirect
8687
)
8788

8889
require (
89-
cloud.google.com/go v0.112.1 // indirect
90-
cloud.google.com/go/compute/metadata v0.3.0 // indirect
91-
cloud.google.com/go/iam v1.1.6 // indirect
92-
cloud.google.com/go/storage v1.38.0 // indirect
93-
github.com/aws/aws-sdk-go v1.44.122 // indirect
94-
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
9590
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
9691
github.com/dustin/go-humanize v1.0.1 // indirect
97-
github.com/felixge/httpsnoop v1.0.4 // indirect
9892
github.com/go-ini/ini v1.67.0 // indirect
99-
github.com/go-logr/logr v1.4.1 // indirect
100-
github.com/go-logr/stdr v1.2.2 // indirect
10193
github.com/goccy/go-json v0.10.4 // indirect
102-
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
103-
github.com/google/s2a-go v0.1.7 // indirect
104-
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
105-
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
106-
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
107-
github.com/hashicorp/go-safetemp v1.0.0 // indirect
108-
github.com/hashicorp/go-version v1.6.0 // indirect
109-
github.com/jmespath/go-jmespath v0.4.0 // indirect
11094
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
11195
github.com/minio/md5-simd v1.1.2 // indirect
112-
github.com/mitchellh/go-homedir v1.1.0 // indirect
11396
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
11497
github.com/robfig/cron/v3 v3.0.1 // indirect
11598
github.com/rogpeppe/go-internal v1.11.0 // indirect
@@ -119,20 +102,9 @@ require (
119102
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
120103
github.com/sirupsen/logrus v1.9.3 // indirect
121104
github.com/sourcegraph/conc v0.3.0 // indirect
122-
github.com/ulikunitz/xz v0.5.10 // indirect
123-
go.opencensus.io v0.24.0 // indirect
124-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
125-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
126-
go.opentelemetry.io/otel v1.24.0 // indirect
127-
go.opentelemetry.io/otel/metric v1.24.0 // indirect
128-
go.opentelemetry.io/otel/trace v1.24.0 // indirect
105+
github.com/stretchr/testify v1.10.0 // indirect
129106
go.uber.org/atomic v1.9.0 // indirect
130107
golang.org/x/exp v0.0.0-20241210194714-1829a127f884 // indirect
131-
golang.org/x/oauth2 v0.20.0 // indirect
132-
golang.org/x/time v0.5.0 // indirect
133-
google.golang.org/api v0.171.0 // indirect
134-
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
135-
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect
136108
)
137109

138110
require (

0 commit comments

Comments
 (0)