allow usage without domain.

This commit is contained in:
Miroslav Šedivý
2021-07-29 21:55:47 +02:00
parent 2f2e28074b
commit 408556f08d
4 changed files with 33 additions and 7 deletions
-1
View File
@@ -43,7 +43,6 @@ You only need `.env.example`, `docker-compose.yml` and `traefik/`.
#### Do I need to use traefik?
- Traefik needs to be used to forward traffic to the rooms. You can put nginx in front of it, but not replace it.
- Your domain name specified for traefik must match the domain name, that your proxy connects to. In docker-compose it is the service name.
- See example configuration for [nginx](docs/nginx).
You can use `docker-compose.http.yml` that will expose this service to `8080` or any port. Authentication is optional.
+2 -2
View File
@@ -27,7 +27,7 @@ services:
- "TZ=Europe/Vienna"
- "NEKO_ROOMS_EPR=59000-59049"
- "NEKO_ROOMS_NAT1TO1=10.8.0.1" # IP address of your server
- "NEKO_ROOMS_TRAEFIK_DOMAIN=traefik" # traefik domain (name of the service)
- "NEKO_ROOMS_TRAEFIK_DOMAIN=*"
- "NEKO_ROOMS_TRAEFIK_ENTRYPOINT=web"
- "NEKO_ROOMS_TRAEFIK_NETWORK=neko-rooms-traefik"
- "NEKO_ROOMS_INSTANCE_URL=https://10.8.0.1:8080/" # external URL
@@ -37,7 +37,7 @@ services:
- "traefik.enable=true"
- "traefik.http.services.neko-rooms-frontend.loadbalancer.server.port=8080"
- "traefik.http.routers.neko-rooms.entrypoints=web"
- "traefik.http.routers.neko-rooms.rule=Host(`traefik`)" # traefik domain (name of the service)
- "traefik.http.routers.neko-rooms.rule=HostRegexp(`{host:.+}`)"
#
# This should be replaced by your own existing nginx instance
+1 -1
View File
@@ -95,7 +95,7 @@ func (Room) Init(cmd *cobra.Command) error {
// Traefik
cmd.PersistentFlags().String("traefik.domain", "neko.lan", "traefik: domain on which will be container hosted")
cmd.PersistentFlags().String("traefik.domain", "", "traefik: domain on which will be container hosted (if empty or '*', match all; for neko-rooms as subdomain use '*.domain.tld')")
if err := viper.BindPFlag("traefik.domain", cmd.PersistentFlags().Lookup("traefik.domain")); err != nil {
return err
}
+30 -3
View File
@@ -147,11 +147,26 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
containerName := manager.config.InstanceName + "-" + roomName
// create traefik rule
traefikRule := "PathPrefix(`/" + roomName + "`)"
if manager.config.TraefikDomain != "" && manager.config.TraefikDomain != "*" {
// match *.domain.tld as subdomain
if strings.HasPrefix(manager.config.TraefikDomain, "*.") {
traefikRule = fmt.Sprintf(
"Host(`%s.%s`)",
roomName,
strings.TrimPrefix(manager.config.TraefikDomain, "*."),
)
} else {
traefikRule += " && Host(`" + manager.config.TraefikDomain + "`)"
}
}
traefikLabels := map[string]string{
"traefik.enable": "true",
"traefik.http.services." + containerName + "-frontend.loadbalancer.server.port": fmt.Sprintf("%d", frontendPort),
"traefik.http.routers." + containerName + ".entrypoints": manager.config.TraefikEntrypoint,
"traefik.http.routers." + containerName + ".rule": "Host(`" + manager.config.TraefikDomain + "`) && PathPrefix(`/" + roomName + "`)",
"traefik.http.routers." + containerName + ".rule": traefikRule,
"traefik.http.middlewares." + containerName + "-rdr.redirectregex.regex": "/" + roomName + "$$",
"traefik.http.middlewares." + containerName + "-rdr.redirectregex.replacement": "/" + roomName + "/",
"traefik.http.middlewares." + containerName + "-prf.stripprefix.prefixes": "/" + roomName + "/",
@@ -169,6 +184,7 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
//
instanceUrl := manager.config.InstanceUrl
instanceSuffix := roomName + "/"
if instanceUrl == "" {
urlProto := "http"
if manager.config.TraefikCertresolver != "" {
@@ -181,14 +197,25 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
port = ":" + manager.config.TraefikPort
}
instanceUrl = urlProto + "://" + manager.config.TraefikDomain + port + "/"
if manager.config.TraefikDomain != "" && manager.config.TraefikDomain != "*" {
// match *.domain.tld as subdomain
if strings.HasPrefix(manager.config.TraefikDomain, "*.") {
instanceUrl = urlProto + "://" + roomName + "." + strings.TrimPrefix(manager.config.TraefikDomain, "*.") + port + "/"
instanceSuffix = ""
} else {
instanceUrl = urlProto + "://" + manager.config.TraefikDomain + port + "/"
}
} else {
// domain is not known
instanceUrl = urlProto + "://127.0.0.1" + port + "/"
}
} else if !strings.HasSuffix(instanceUrl, "/") {
instanceUrl = instanceUrl + "/"
}
labels := manager.serializeLabels(RoomLabels{
Name: roomName,
URL: instanceUrl + roomName + "/",
URL: instanceUrl + instanceSuffix,
Epr: epr,
NekoImage: settings.NekoImage,
})