feat: implement websocket and UI

This commit is contained in:
Oarkflow
2024-10-22 21:12:55 +05:45
parent 05a673bcd6
commit f337e00b88
21 changed files with 1880 additions and 33 deletions

View File

@@ -3,6 +3,7 @@ package dag
import (
"encoding/json"
"fmt"
"github.com/oarkflow/mq/sio"
"io"
"net/http"
"os"
@@ -21,8 +22,20 @@ type Request struct {
Recurring bool `json:"recurring"`
}
func (tm *DAG) SetupWS() *sio.Server {
ws := sio.New(sio.Config{
CheckOrigin: func(r *http.Request) bool { return true },
EnableCompression: true,
})
WsEvents(ws)
tm.Notifier = ws
return ws
}
func (tm *DAG) Handlers() {
metrics.HandleHTTP()
http.Handle("/", http.FileServer(http.Dir("webroot")))
http.Handle("/notify", tm.SetupWS())
http.HandleFunc("POST /request", tm.Request)
http.HandleFunc("POST /publish", tm.Publish)
http.HandleFunc("POST /schedule", tm.Schedule)