mirror of
https://github.com/m1k1o/neko-rooms.git
synced 2026-11-02 22:51:34 -06:00
Merge branch 'master' into custom-labels
This commit is contained in:
@@ -11,3 +11,13 @@ All clients visit `https://neko-rooms/room-name/`. Once they logged in, they get
|
|||||||
## Connection timeout
|
## Connection timeout
|
||||||
|
|
||||||
Neko room loads but you don't see the screen and it gives you `connection timeout` or `disconnected error`? [Validate](https://neko.m1k1o.net/#/getting-started/troubleshooting?id=validate-udp-ports-reachability) that your UDP ports are reachable.
|
Neko room loads but you don't see the screen and it gives you `connection timeout` or `disconnected error`? [Validate](https://neko.m1k1o.net/#/getting-started/troubleshooting?id=validate-udp-ports-reachability) that your UDP ports are reachable.
|
||||||
|
|
||||||
|
## path prefix
|
||||||
|
|
||||||
|
Room names are by default put to root directory. If you want to have custom path prefix, you can specify it using env variable:
|
||||||
|
|
||||||
|
```
|
||||||
|
NEKO_ROOMS_PATH_PREFIX=/test/
|
||||||
|
```
|
||||||
|
|
||||||
|
Now room will be available at `example.org/test/<room-name>` instead of `example.org/<room-name>`.
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ type Room struct {
|
|||||||
|
|
||||||
NAT1To1IPs []string
|
NAT1To1IPs []string
|
||||||
NekoImages []string
|
NekoImages []string
|
||||||
|
PathPrefix string
|
||||||
Labels []string
|
Labels []string
|
||||||
|
|
||||||
StorageEnabled bool
|
StorageEnabled bool
|
||||||
@@ -62,6 +63,11 @@ func (Room) Init(cmd *cobra.Command) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.PersistentFlags().String("path_prefix", "", "path prefix that is added to every room path")
|
||||||
|
if err := viper.BindPFlag("path_prefix", cmd.PersistentFlags().Lookup("path_prefix")); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
cmd.PersistentFlags().StringSlice("labels", []string{}, "additional labels appended to every room")
|
cmd.PersistentFlags().StringSlice("labels", []string{}, "additional labels appended to every room")
|
||||||
if err := viper.BindPFlag("labels", cmd.PersistentFlags().Lookup("labels")); err != nil {
|
if err := viper.BindPFlag("labels", cmd.PersistentFlags().Lookup("labels")); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -158,6 +164,7 @@ func (s *Room) Set() {
|
|||||||
|
|
||||||
s.NAT1To1IPs = viper.GetStringSlice("nat1to1")
|
s.NAT1To1IPs = viper.GetStringSlice("nat1to1")
|
||||||
s.NekoImages = viper.GetStringSlice("neko_images")
|
s.NekoImages = viper.GetStringSlice("neko_images")
|
||||||
|
s.PathPrefix = viper.GetString("path_prefix")
|
||||||
s.Labels = viper.GetStringSlice("labels")
|
s.Labels = viper.GetStringSlice("labels")
|
||||||
|
|
||||||
s.StorageEnabled = viper.GetBool("storage.enabled")
|
s.StorageEnabled = viper.GetBool("storage.enabled")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
"github.com/go-chi/chi"
|
"github.com/go-chi/chi"
|
||||||
"github.com/go-chi/chi/middleware"
|
"github.com/go-chi/chi/middleware"
|
||||||
@@ -22,7 +23,7 @@ type HttpManagerCtx struct {
|
|||||||
conf *config.Server
|
conf *config.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(ApiManager types.ApiManager, conf *config.Server) *HttpManagerCtx {
|
func New(ApiManager types.ApiManager, pathPrefix string, conf *config.Server) *HttpManagerCtx {
|
||||||
logger := log.With().Str("module", "http").Logger()
|
logger := log.With().Str("module", "http").Logger()
|
||||||
|
|
||||||
router := chi.NewRouter()
|
router := chi.NewRouter()
|
||||||
@@ -54,8 +55,8 @@ func New(ApiManager types.ApiManager, conf *config.Server) *HttpManagerCtx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add simple lobby room
|
// add simple lobby room
|
||||||
router.Get("/{roomName}", ApiManager.RoomLobby)
|
router.Get(path.Join("/", pathPrefix, "{roomName}"), ApiManager.RoomLobby)
|
||||||
router.Get("/{roomName}/", ApiManager.RoomLobby)
|
router.Get(path.Join("/", pathPrefix, "{roomName}")+"/", ApiManager.RoomLobby)
|
||||||
|
|
||||||
router.NotFound(http.HandlerFunc(http.NotFound))
|
router.NotFound(http.HandlerFunc(http.NotFound))
|
||||||
|
|
||||||
|
|||||||
+13
-12
@@ -149,9 +149,10 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
|
|||||||
//
|
//
|
||||||
|
|
||||||
containerName := manager.config.InstanceName + "-" + roomName
|
containerName := manager.config.InstanceName + "-" + roomName
|
||||||
|
pathPrefix := path.Join("/", manager.config.PathPrefix, roomName)
|
||||||
|
|
||||||
// create traefik rule
|
// create traefik rule
|
||||||
traefikRule := "PathPrefix(`/" + roomName + "`)"
|
traefikRule := "PathPrefix(`" + pathPrefix + "`)"
|
||||||
if manager.config.TraefikDomain != "" && manager.config.TraefikDomain != "*" {
|
if manager.config.TraefikDomain != "" && manager.config.TraefikDomain != "*" {
|
||||||
// match *.domain.tld as subdomain
|
// match *.domain.tld as subdomain
|
||||||
if strings.HasPrefix(manager.config.TraefikDomain, "*.") {
|
if strings.HasPrefix(manager.config.TraefikDomain, "*.") {
|
||||||
@@ -172,9 +173,9 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
|
|||||||
"traefik.http.services." + containerName + "-frontend.loadbalancer.server.port": fmt.Sprintf("%d", frontendPort),
|
"traefik.http.services." + containerName + "-frontend.loadbalancer.server.port": fmt.Sprintf("%d", frontendPort),
|
||||||
"traefik.http.routers." + containerName + ".entrypoints": manager.config.TraefikEntrypoint,
|
"traefik.http.routers." + containerName + ".entrypoints": manager.config.TraefikEntrypoint,
|
||||||
"traefik.http.routers." + containerName + ".rule": traefikRule,
|
"traefik.http.routers." + containerName + ".rule": traefikRule,
|
||||||
"traefik.http.middlewares." + containerName + "-rdr.redirectregex.regex": "/" + roomName + "$$",
|
"traefik.http.middlewares." + containerName + "-rdr.redirectregex.regex": pathPrefix + "$$",
|
||||||
"traefik.http.middlewares." + containerName + "-rdr.redirectregex.replacement": "/" + roomName + "/",
|
"traefik.http.middlewares." + containerName + "-rdr.redirectregex.replacement": pathPrefix + "/",
|
||||||
"traefik.http.middlewares." + containerName + "-prf.stripprefix.prefixes": "/" + roomName + "/",
|
"traefik.http.middlewares." + containerName + "-prf.stripprefix.prefixes": pathPrefix + "/",
|
||||||
"traefik.http.routers." + containerName + ".middlewares": containerName + "-rdr," + containerName + "-prf",
|
"traefik.http.routers." + containerName + ".middlewares": containerName + "-rdr," + containerName + "-prf",
|
||||||
"traefik.http.routers." + containerName + ".service": containerName + "-frontend",
|
"traefik.http.routers." + containerName + ".service": containerName + "-frontend",
|
||||||
}
|
}
|
||||||
@@ -190,7 +191,6 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
|
|||||||
//
|
//
|
||||||
|
|
||||||
instanceUrl := manager.config.InstanceUrl
|
instanceUrl := manager.config.InstanceUrl
|
||||||
instanceSuffix := roomName + "/"
|
|
||||||
if instanceUrl == "" {
|
if instanceUrl == "" {
|
||||||
urlProto := "http"
|
urlProto := "http"
|
||||||
if manager.config.TraefikCertresolver != "" {
|
if manager.config.TraefikCertresolver != "" {
|
||||||
@@ -206,19 +206,20 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
|
|||||||
if manager.config.TraefikDomain != "" && manager.config.TraefikDomain != "*" {
|
if manager.config.TraefikDomain != "" && manager.config.TraefikDomain != "*" {
|
||||||
// match *.domain.tld as subdomain
|
// match *.domain.tld as subdomain
|
||||||
if strings.HasPrefix(manager.config.TraefikDomain, "*.") {
|
if strings.HasPrefix(manager.config.TraefikDomain, "*.") {
|
||||||
instanceUrl = urlProto + "://" + roomName + "." + strings.TrimPrefix(manager.config.TraefikDomain, "*.") + port + "/"
|
instanceUrl = urlProto + "://" + roomName + "." + strings.TrimPrefix(manager.config.TraefikDomain, "*.") + port
|
||||||
instanceSuffix = ""
|
pathPrefix = ""
|
||||||
} else {
|
} else {
|
||||||
instanceUrl = urlProto + "://" + manager.config.TraefikDomain + port + "/"
|
instanceUrl = urlProto + "://" + manager.config.TraefikDomain + port
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// domain is not known
|
// domain is not known
|
||||||
instanceUrl = urlProto + "://127.0.0.1" + port + "/"
|
instanceUrl = urlProto + "://127.0.0.1" + port
|
||||||
}
|
}
|
||||||
} else if !strings.HasSuffix(instanceUrl, "/") {
|
|
||||||
instanceUrl = instanceUrl + "/"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove last slash
|
||||||
|
instanceUrl = strings.TrimSuffix(instanceUrl, "/")
|
||||||
|
|
||||||
var browserPolicyLabels *BrowserPolicyLabels
|
var browserPolicyLabels *BrowserPolicyLabels
|
||||||
if settings.BrowserPolicy != nil {
|
if settings.BrowserPolicy != nil {
|
||||||
browserPolicyLabels = &BrowserPolicyLabels{
|
browserPolicyLabels = &BrowserPolicyLabels{
|
||||||
@@ -229,7 +230,7 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
|
|||||||
|
|
||||||
labels := manager.serializeLabels(RoomLabels{
|
labels := manager.serializeLabels(RoomLabels{
|
||||||
Name: roomName,
|
Name: roomName,
|
||||||
URL: instanceUrl + instanceSuffix,
|
URL: instanceUrl + pathPrefix + "/",
|
||||||
Epr: epr,
|
Epr: epr,
|
||||||
NekoImage: settings.NekoImage,
|
NekoImage: settings.NekoImage,
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user