BareRTC/pkg/server.go
Noah Petherbridge e728644a77 Port front-end over to Vue CLI (create-vue)
This commit makes an initial port of the front-end over to a proper Vue
CLI application. It seems to work from surface level testing.

Changes made:

* Rename web/static to public/static to place it into the Vue build path
  * Notes: web/static/js/BareRTC.js and web/templates/chat.html are now
    deprecated
* Rename web/static/js/sounds.js into src/lib/sounds.js making it a
  proper JavaScript module with exports.
* Fill out initial src/App.vue by copying and updating
  web/templates/chat.html and web/static/js/BareRTC.js into this module.
2023-09-06 17:15:02 -07:00

52 lines
1.3 KiB
Go

package barertc
import (
"net/http"
"sync"
)
// Server is the primary back-end server struct for BareRTC, see main.go
type Server struct {
// HTTP router.
mux *http.ServeMux
// Max number of messages we'll buffer for a subscriber
subscriberMessageBuffer int
// Connected WebSocket subscribers.
subscribersMu sync.RWMutex
subscribers map[*Subscriber]struct{}
}
// NewServer initializes the Server.
func NewServer() *Server {
return &Server{
subscriberMessageBuffer: 16,
subscribers: make(map[*Subscriber]struct{}),
}
}
// Setup the server: configure HTTP routes, etc.
func (s *Server) Setup() error {
var mux = http.NewServeMux()
mux.Handle("/", IndexPage())
mux.Handle("/about", AboutPage())
mux.Handle("/ws", s.WebSocket())
mux.Handle("/api/statistics", s.Statistics())
mux.Handle("/api/blocklist", s.BlockList())
mux.Handle("/api/authenticate", s.Authenticate())
mux.Handle("/api/shutdown", s.ShutdownAPI())
mux.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("dist/assets"))))
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("dist/static"))))
s.mux = mux
return nil
}
// ListenAndServe starts the web server.
func (s *Server) ListenAndServe(address string) error {
return http.ListenAndServe(address, s.mux)
}