mukan-ignite/ignite/pkg/cosmosfaucet/http.go
Mukan Erkin Törük 26b204bd04
Some checks are pending
Docs Deploy / build_and_deploy (push) Waiting to run
Generate Docs / cli (push) Waiting to run
Generate Config Doc / cli (push) Waiting to run
Go formatting / go-formatting (push) Waiting to run
Check links / markdown-link-check (push) Waiting to run
Integration / pre-test (push) Waiting to run
Integration / test on (push) Blocked by required conditions
Integration / status (push) Blocked by required conditions
Lint / Lint Go code (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
feat: fork Ignite CLI v29 as Mukan Ignite — remove cosmos-sdk restrictions
2026-05-11 03:31:37 +03:00

44 lines
1.2 KiB
Go

package cosmosfaucet
import (
"net/http"
"github.com/rs/cors"
"github.com/ignite/cli/v29/ignite/pkg/openapiconsole"
)
// ServeHTTP implements http.Handler to expose the functionality of Faucet.Transfer() via HTTP.
// request/response payloads are compatible with the previous implementation at allinbits/cosmos-faucet.
func (f Faucet) ServeHTTP(w http.ResponseWriter, r *http.Request) {
mux := http.NewServeMux()
mux.Handle("/", cors.Default().Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch {
case r.Method == http.MethodPost || r.Method == http.MethodOptions:
f.faucetHandler(w, r)
case r.Method == http.MethodGet:
openapiconsole.Handler("Faucet", "openapi.yml")(w, r)
default:
http.NotFound(w, r)
}
})))
mux.Handle("/info", cors.Default().Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet || r.Method == http.MethodOptions {
f.faucetInfoHandler(w, r)
} else {
http.NotFound(w, r)
}
})))
mux.HandleFunc("/openapi.yml", func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
f.openAPISpecHandler(w, r)
} else {
http.NotFound(w, r)
}
})
mux.ServeHTTP(w, r)
}