mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-19 02:03:40 -05:00
config: make origin patterns configurable
This commit is contained in:
parent
68f8d4d372
commit
cd4655ac38
2 changed files with 12 additions and 7 deletions
|
@ -42,12 +42,13 @@ type MatrixConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebConfig struct {
|
type WebConfig struct {
|
||||||
ListenAddress string `yaml:"listen_address"`
|
ListenAddress string `yaml:"listen_address"`
|
||||||
Username string `yaml:"username"`
|
Username string `yaml:"username"`
|
||||||
PasswordHash string `yaml:"password_hash"`
|
PasswordHash string `yaml:"password_hash"`
|
||||||
TokenKey string `yaml:"token_key"`
|
TokenKey string `yaml:"token_key"`
|
||||||
DebugEndpoints bool `yaml:"debug_endpoints"`
|
DebugEndpoints bool `yaml:"debug_endpoints"`
|
||||||
EventBufferSize int `yaml:"event_buffer_size"`
|
EventBufferSize int `yaml:"event_buffer_size"`
|
||||||
|
OriginPatterns []string `yaml:"origin_patterns"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultFileWriter = zeroconfig.WriterConfig{
|
var defaultFileWriter = zeroconfig.WriterConfig{
|
||||||
|
@ -120,6 +121,10 @@ func (gmx *Gomuks) LoadConfig() error {
|
||||||
gmx.Config.Web.EventBufferSize = 512
|
gmx.Config.Web.EventBufferSize = 512
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
|
if len(gmx.Config.Web.OriginPatterns) == 0 {
|
||||||
|
gmx.Config.Web.OriginPatterns = []string{"localhost:*", "*.localhost:*"}
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
if changed {
|
if changed {
|
||||||
err = gmx.SaveConfig()
|
err = gmx.SaveConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -86,7 +86,7 @@ func (gmx *Gomuks) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
|
||||||
defer recoverPanic("read loop")
|
defer recoverPanic("read loop")
|
||||||
|
|
||||||
conn, acceptErr := websocket.Accept(w, r, &websocket.AcceptOptions{
|
conn, acceptErr := websocket.Accept(w, r, &websocket.AcceptOptions{
|
||||||
OriginPatterns: []string{"localhost:*"},
|
OriginPatterns: gmx.Config.Web.OriginPatterns,
|
||||||
})
|
})
|
||||||
if acceptErr != nil {
|
if acceptErr != nil {
|
||||||
log.Warn().Err(acceptErr).Msg("Failed to accept websocket connection")
|
log.Warn().Err(acceptErr).Msg("Failed to accept websocket connection")
|
||||||
|
|
Loading…
Add table
Reference in a new issue