Skip to content

Commit

Permalink
fix(local-ic): pesky cors (#1226)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups authored Aug 22, 2024
1 parent 2f1634e commit c3e1187
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions local-interchain/interchain/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"sync"
"syscall"

"github.com/gorilla/handlers"
"github.com/strangelove-ventures/interchaintest/local-interchain/interchain/router"
"github.com/strangelove-ventures/interchaintest/local-interchain/interchain/types"
"github.com/strangelove-ventures/interchaintest/v8"
Expand Down Expand Up @@ -244,8 +245,25 @@ func StartChain(installDir, chainCfgFile string, ac *types.AppStartConfig) {
Port: fmt.Sprintf("%d", ac.Port),
}

server := fmt.Sprintf("%s:%s", config.Server.Host, config.Server.Port)
if err := http.ListenAndServe(server, r); err != nil {
if config.Server.Host == "" {
config.Server.Host = "127.0.0.1"
}
if config.Server.Port == "" {
config.Server.Port = "8080"
}

serverAddr := fmt.Sprintf("%s:%s", config.Server.Host, config.Server.Port)

// Where ORIGIN_ALLOWED is like `scheme://dns[:port]`, or `*` (insecure)
corsHandler := handlers.CORS(
handlers.AllowedOrigins([]string{"*"}),
handlers.AllowedHeaders([]string{"*"}),
handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS", "DELETE"}),
handlers.AllowCredentials(),
handlers.ExposedHeaders([]string{"*"}),
)

if err := http.ListenAndServe(serverAddr, corsHandler(r)); err != nil {
log.Default().Println(err)
}
}()
Expand Down

0 comments on commit c3e1187

Please sign in to comment.