forked from Mirrors/gomuks
config: make origin patterns configurable
This commit is contained in:
parent
68f8d4d372
commit
cd4655ac38
2 changed files with 12 additions and 7 deletions
|
@ -48,6 +48,7 @@ type WebConfig struct {
|
||||||
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