/
main.go
44 lines (37 loc) · 1.3 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
package main
import (
"fmt"
"log"
"net/http"
"net/http/httputil"
"net/url"
"github.com/chneau/remoteav/common"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/graph-gophers/graphql-go"
"github.com/graph-gophers/graphql-go/relay"
"github.com/samber/lo"
)
func main() {
log.SetFlags(log.LstdFlags | log.Llongfile)
resolver := common.NewResolver()
schema := graphql.MustParseSchema(common.SchemaString, resolver)
router := chi.NewRouter()
router.Use(middleware.RequestID)
router.Use(middleware.RealIP)
router.Use(middleware.Recoverer)
router.Use(middleware.CleanPath)
router.Use(middleware.GetHead)
router.Use(middleware.StripSlashes)
router.Use(middleware.Compress(5))
router.With(middleware.Logger).Handle("/graphql", &relay.Handler{Schema: schema})
router.Get("/graphiql", graphiqlHandler)
router.Get("/*", httputil.NewSingleHostReverseProxy(lo.Must(url.Parse("http://localhost:5173"))).ServeHTTP)
router.Get(common.VideoPath, common.StreamVideoHandler(resolver.VideoStream()))
router.Get(common.AudioPath, common.StreamAudioHandler(resolver.AudioStream()))
fmt.Println("Listening on port http://localhost:7777")
lo.Must0(http.ListenAndServe(":7777", router))
}
func graphiqlHandler(w http.ResponseWriter, r *http.Request) {
lo.Must(w.Write(common.GraphiqlHTML))
}