debug needed
This commit is contained in:
@@ -25,7 +25,7 @@ func (s *Server) getInstruction(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (s *Server) exchangeSDP(c *gin.Context) {
|
||||
var offer *webrtc.SessionDescription
|
||||
offer := &webrtc.SessionDescription{}
|
||||
if err := c.BindJSON(offer); err != nil {
|
||||
c.JSON(http.StatusBadRequest, Response{
|
||||
Succeed: false,
|
||||
|
@@ -1,12 +1,30 @@
|
||||
package webserver
|
||||
|
||||
import "github.com/gin-contrib/static"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (s *Server) setupRoute() {
|
||||
s.webServer.
|
||||
Use(static.Serve("/", newFS())).
|
||||
POST("/api/v1/sdp", s.exchangeSDP).
|
||||
GET("/api/v1/instruction", s.getInstruction).
|
||||
GET("/api/v1/iceserver/url", s.getICEConfig).
|
||||
GET("/api/v1/name", s.getName)
|
||||
apiHandler := gin.New()
|
||||
groupV1 := apiHandler.Group("/api/v1")
|
||||
{
|
||||
groupV1.
|
||||
POST("/sdp", s.exchangeSDP).
|
||||
GET("/instruction", s.getInstruction).
|
||||
GET("/iceserver/url", s.getICEConfig).
|
||||
GET("/name", s.getName)
|
||||
}
|
||||
|
||||
s.webServer.Use(func(ctx *gin.Context) {
|
||||
path := ctx.Request.RequestURI
|
||||
logrus.Debug(path)
|
||||
if strings.HasPrefix(path, "/api") {
|
||||
apiHandler.HandleContext(ctx)
|
||||
} else {
|
||||
staticFileHandler()(ctx)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@@ -5,33 +5,33 @@ import (
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
//go:generate cp -r ../../web/dist ./
|
||||
//go:embed dist
|
||||
var staticFiles embed.FS
|
||||
|
||||
type ginFS struct {
|
||||
fs http.FileSystem
|
||||
}
|
||||
|
||||
func newFS() *ginFS {
|
||||
f, _ := fs.Sub(staticFiles, "dist")
|
||||
return &ginFS{
|
||||
fs: http.FS(f),
|
||||
func staticFileHandler() gin.HandlerFunc {
|
||||
sf, err := fs.Sub(staticFiles, "dist")
|
||||
if err != nil {
|
||||
logrus.Fatal("compile error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ginFS) Exists(prefix string, filepath string) bool {
|
||||
if p := strings.TrimPrefix(filepath, prefix); len(p) < len(filepath) {
|
||||
if _, err := s.fs.Open(p); err != nil {
|
||||
return false
|
||||
fs := http.FileServer(http.FS(sf))
|
||||
|
||||
return func(ctx *gin.Context) {
|
||||
defer ctx.Abort()
|
||||
filename := strings.TrimLeft(ctx.Request.RequestURI, "/")
|
||||
|
||||
logrus.Debug("static file: ", filename)
|
||||
|
||||
if filename == "" {
|
||||
filename = "index.html"
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *ginFS) Open(name string) (http.File, error) {
|
||||
return s.fs.Open(name)
|
||||
fs.ServeHTTP(ctx.Writer, ctx.Request)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user