diff --git a/api/server.go b/api/server.go index 12dc4cfb..ef403eed 100644 --- a/api/server.go +++ b/api/server.go @@ -4,8 +4,11 @@ import ( "context" _ "embed" "fmt" + "math/rand" "net" "net/http" + "net/http/httputil" + "net/url" "os" "os/signal" "reflect" @@ -595,6 +598,25 @@ func NewApiServer(config config.Config) *ApiServer { // Unsplash proxy app.All("/unsplash/*", app.unsplash) + // Archiver proxy + if len(config.ArchiverNodes) > 0 { + app.All("/archive/*", func(c *fiber.Ctx) error { + randIdx := rand.Intn(len(config.ArchiverNodes)) + upstreamUrl := config.ArchiverNodes[randIdx] + upstream, err := url.Parse(upstreamUrl) + if err != nil { + return fiber.NewError(fiber.StatusBadGateway, "Invalid Archiver upstream url") + } + proxy := httputil.NewSingleHostReverseProxy(upstream) + origDirector := proxy.Director + proxy.Director = func(req *http.Request) { + origDirector(req) + req.Host = upstream.Host + } + return adaptor.HTTPHandler(proxy)(c) + }) + } + app.Static("/", "./static") // Disable swagger in test environments, because it will slow things down a lot diff --git a/config/config.go b/config/config.go index a92cd28a..df332c50 100644 --- a/config/config.go +++ b/config/config.go @@ -34,6 +34,7 @@ type Config struct { NetworkTakeRate float64 SolanaConfig SolanaConfig AntiAbuseOracles []string + ArchiverNodes []string Rewards []rewards.Reward AudiusdURL string OpenAudioURLs []string @@ -99,6 +100,7 @@ func init() { Cfg.DelegatePrivateKey = "13422b9affd75ff80f94f1ea394e6a6097830cb58cda2d3542f37464ecaee7df" } Cfg.AntiAbuseOracles = []string{"http://audius-discovery-provider-1"} + Cfg.ArchiverNodes = []string{"http://audius-discovery-provider-1"} Cfg.Rewards = core_config.MakeRewards(core_config.DevClaimAuthorities, core_config.DevRewardExtensions) Cfg.AudiusdURL = "http://audius-creator-node-1" Cfg.ChainId = "audius-devnet" @@ -121,6 +123,7 @@ func init() { log.Fatalf("Missing required %s env var: delegatePrivateKey", env) } Cfg.AntiAbuseOracles = []string{"https://discoveryprovider.staging.audius.co"} + Cfg.ArchiverNodes = []string{"https://discoveryprovider.staging.audius.co"} Cfg.DeadNodes = []string{} Cfg.StoreAllNodes = []string{} Cfg.UploadNodes = StageUploadNodes @@ -162,6 +165,7 @@ func init() { log.Fatalf("Missing required %s env var: delegatePrivateKey", env) } Cfg.AntiAbuseOracles = []string{"https://discoveryprovider.audius.co"} + Cfg.ArchiverNodes = []string{"https://discoveryprovider.audius.co"} Cfg.DeadNodes = []string{ "https://content.grassfed.network", }