Skip to content

Commit

Permalink
update faucet to include cors
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol1696 committed Oct 17, 2024
1 parent 4861959 commit 7b95507
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions starship/charts/devnet/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,9 @@ defaultChains:
name: Hyper
display: hyper
symbol: HYPR
logo_URIs:
png: "https://gist.githubusercontent.com/Anmol1696/bea1b3835dfb0fce3ab9ed993f5a0792/raw/7065493384a51c888752284be7c1afbf6135b50a/logo-png.png"
svg: "https://gist.githubusercontent.com/Anmol1696/bea1b3835dfb0fce3ab9ed993f5a0792/raw/7065493384a51c888752284be7c1afbf6135b50a/logo-svg.svg"
denom_units:
- denom: uhyper
exponent: 0
Expand Down
15 changes: 14 additions & 1 deletion starship/faucet/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/go-chi/chi/middleware"
"github.com/go-chi/cors"
grpcmiddleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpczap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
grpcrecovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
Expand Down Expand Up @@ -83,7 +84,7 @@ func NewAppServer(config *Config) (*AppServer, error) {
}
httpServer := &http.Server{
Addr: fmt.Sprintf("%s:%s", config.Host, config.HTTPPort),
Handler: app.panicRecovery(app.loggingMiddleware(mux)),
Handler: app.panicRecovery(app.corsMiddleware(app.loggingMiddleware(mux))),
}
app.httpServer = httpServer

Expand Down Expand Up @@ -186,6 +187,18 @@ func (a *AppServer) panicRecovery(next http.Handler) http.Handler {
return http.HandlerFunc(fn)
}

func (a *AppServer) corsMiddleware(next http.Handler) http.Handler {
corsOptions := cors.Options{
AllowedOrigins: []string{"*"}, // Adjust this to your needs
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
ExposedHeaders: []string{"Link"},
AllowCredentials: true,
MaxAge: 300, // Maximum value not ignored by any of major browsers
}
return cors.New(corsOptions).Handler(next)
}

func (a *AppServer) Run() error {
a.logger.Info("App starting", zap.Any("config", a.config))

Expand Down

0 comments on commit 7b95507

Please sign in to comment.