@@ -4,11 +4,8 @@ import (
44 "context"
55 _ "embed"
66 "fmt"
7- "math/rand"
87 "net"
98 "net/http"
10- "net/http/httputil"
11- "net/url"
129 "os"
1310 "os/signal"
1411 "reflect"
@@ -305,6 +302,12 @@ func NewApiServer(config config.Config) *ApiServer {
305302 return c .JSON (app .metricsCollector .Debug ())
306303 })
307304
305+ // Unsplash proxy
306+ app .All ("/unsplash/*" , app .unsplash )
307+
308+ // Archiver proxy
309+ app .All ("/archive/*" , archiveProxy )
310+
308311 // resolve myId
309312 app .Use (app .isFullMiddleware )
310313 app .Use (app .resolveMyIdMiddleware )
@@ -595,28 +598,6 @@ func NewApiServer(config config.Config) *ApiServer {
595598 app .Get ("/content/verbose" , app .contentNodes )
596599 app .Get ("/content-nodes/verbose" , app .contentNodes )
597600
598- // Unsplash proxy
599- app .All ("/unsplash/*" , app .unsplash )
600-
601- // Archiver proxy
602- if len (config .ArchiverNodes ) > 0 {
603- app .All ("/archive/*" , func (c * fiber.Ctx ) error {
604- randIdx := rand .Intn (len (config .ArchiverNodes ))
605- upstreamUrl := config .ArchiverNodes [randIdx ]
606- upstream , err := url .Parse (upstreamUrl )
607- if err != nil {
608- return fiber .NewError (fiber .StatusBadGateway , "Invalid Archiver upstream url" )
609- }
610- proxy := httputil .NewSingleHostReverseProxy (upstream )
611- origDirector := proxy .Director
612- proxy .Director = func (req * http.Request ) {
613- origDirector (req )
614- req .Host = upstream .Host
615- }
616- return adaptor .HTTPHandler (proxy )(c )
617- })
618- }
619-
620601 app .Static ("/" , "./static" )
621602
622603 // Disable swagger in test environments, because it will slow things down a lot
0 commit comments