BREAKING Change to single page url

This commit is contained in:
Florian Hoss 2022-11-27 10:03:58 +01:00
parent bc3e957ce7
commit 7bf3093792
5 changed files with 10 additions and 20 deletions

View file

@ -58,7 +58,7 @@ The name and related link can be provided as well.
```toml
PORT = 4000
ALLOWED_HOSTS = "http://localhost:4000"
PAGE_URL = "http://localhost:4000"
TITLE = "GoDash"
LOG_LEVEL = "info"
@ -89,8 +89,7 @@ services:
- PUID=1000
- PGID=1000
- TZ=Europe/Berlin
# can be multiple hosts, comma separated, no spaces
- ALLOWED_HOSTS=https://home.example.com
- PAGE_URL=https://home.example.com
# change title to something else
- TITLE=GoDash
# available log-levels: trace,debug,info,warn,error,fatal,panic

View file

@ -1,5 +1,5 @@
{
"port": 4000,
"allowed_hosts": "http://localhost:4000",
"PAGE_URL": "http://localhost:4000",
"title": "GoDash"
}

View file

@ -19,7 +19,7 @@ func (server *Server) setupMiddlewares() {
server.Router.Use(middleware.AllowContentEncoding("deflate", "gzip"))
server.Router.Use(middleware.Compress(5, "text/html", "text/js", "text/css"))
server.Router.Use(cors.Handler(cors.Options{
AllowedOrigins: server.AllowedHosts,
AllowedOrigins: []string{server.PageUrl},
AllowedMethods: []string{"GET", "OPTIONS"},
AllowedHeaders: []string{"Accept-Encoding", "Content-Type"},
AllowCredentials: false,

View file

@ -6,9 +6,9 @@ import (
)
type Server struct {
Router *chi.Mux
Hub *hub.Hub
Port int
AllowedHosts []string `mapstructure:"ALLOWED_HOSTS"`
Title string
Router *chi.Mux
Hub *hub.Hub
Port int
PageUrl string `mapstructure:"PAGE_URL"`
Title string
}

View file

@ -5,18 +5,9 @@ import (
"net/http"
)
func inAllowedHosts(str string) bool {
for _, a := range server.AllowedHosts {
if a == str {
return true
}
}
return false
}
var upgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool {
return inAllowedHosts(r.Header.Get("Origin"))
return server.PageUrl == r.Header.Get("Origin")
},
ReadBufferSize: 1024,
WriteBufferSize: 1024,