speed + more config
This commit is contained in:
@@ -161,13 +161,13 @@ func handleMessage(msg string, ws *websocket.Conn) error {
|
||||
func InitWs(c echo.Context) error {
|
||||
websocket.Handler(func(ws *websocket.Conn) {
|
||||
wsMutex.Lock()
|
||||
wsConnections[ws] = c.RealIP()
|
||||
wsConnections[ws] = c.Request().UserAgent()
|
||||
wsMutex.Unlock()
|
||||
|
||||
boxes := GetBoxes()
|
||||
msg := "u:" + strconv.Itoa(len(wsConnections)) + ":"
|
||||
for _, addr := range wsConnections {
|
||||
msg += addr + ","
|
||||
msg += addr + ",,,"
|
||||
}
|
||||
msg += "\n"
|
||||
|
||||
|
||||
15
src/main.go
15
src/main.go
@@ -3,6 +3,9 @@ package main
|
||||
import (
|
||||
"html/template"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
@@ -47,9 +50,21 @@ func main() {
|
||||
|
||||
e.Logger.SetLevel(log.DEBUG)
|
||||
e.Use(middleware.Logger())
|
||||
e.Use(middleware.Gzip())
|
||||
e.Use(middleware.HTTPSRedirect())
|
||||
|
||||
e.GET("/health", healthCheck)
|
||||
|
||||
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
if strings.HasPrefix(c.Request().URL.Path, "/css/") || strings.HasPrefix(c.Request().URL.Path, "/js/") {
|
||||
c.Response().Header().Set("Cache-Control", "public, max-age=31536000") // 1 year
|
||||
c.Response().Header().Set("Expires", time.Now().AddDate(1, 0, 0).Format(http.TimeFormat))
|
||||
}
|
||||
return next(c)
|
||||
}
|
||||
})
|
||||
|
||||
e.Static("/css", "css")
|
||||
e.Static("/js", "js")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user