Skip to content

Commit 4b96d7f

Browse files
authored
Explicitly proxy some ambigious routes. (#30)
1 parent bd2ab7d commit 4b96d7f

2 files changed

Lines changed: 42 additions & 17 deletions

File tree

api/server.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,26 @@ func NewApiServer(config config.Config) *ApiServer {
117117
app.Use(app.resolveMyIdMiddleware)
118118
app.Use(app.authMiddleware)
119119

120+
// some not-yet-implemented routes will match handlers below
121+
// and won't fall thru to python reverse proxy handler
122+
// so add some exclusions here to make `bridge.audius.co` less broken
123+
// todo: implement these endpoints in bridgerton.
124+
{
125+
app.Use("/v1/full/users/top", BalancerForward(config.PythonUpstreams))
126+
app.Use("/v1/full/users/genre/top", BalancerForward(config.PythonUpstreams))
127+
app.Use("/v1/full/users/subscribers", BalancerForward(config.PythonUpstreams))
128+
129+
app.Use("/v1/full/playlists/top", BalancerForward(config.PythonUpstreams))
130+
app.Use("/v1/full/playlists/trending", BalancerForward(config.PythonUpstreams))
131+
132+
app.Use("/v1/full/tracks/best_new_releases", BalancerForward(config.PythonUpstreams))
133+
app.Use("/v1/full/tracks/feeling_lucky", BalancerForward(config.PythonUpstreams))
134+
app.Use("/v1/full/tracks/most_loved", BalancerForward(config.PythonUpstreams))
135+
app.Use("/v1/full/tracks/remixables", BalancerForward(config.PythonUpstreams))
136+
app.Use("/v1/full/tracks/usdc-purchase", BalancerForward(config.PythonUpstreams))
137+
app.Use("/v1/full/tracks/trending/underground", BalancerForward(config.PythonUpstreams))
138+
}
139+
120140
v1 := app.Group("/v1")
121141
v1Full := app.Group("/v1/full")
122142

@@ -173,23 +193,7 @@ func NewApiServer(config config.Config) *ApiServer {
173193
app.Static("/", "./static")
174194

175195
// proxy unhandled requests thru to existing discovery API
176-
{
177-
upstreams := []string{
178-
"https://discoveryprovider.audius.co",
179-
"https://discoveryprovider2.audius.co",
180-
"https://discoveryprovider3.audius.co",
181-
}
182-
if os.Getenv("ENV") == "stage" {
183-
upstreams = []string{
184-
"https://discoveryprovider.staging.audius.co",
185-
"https://discoveryprovider2.staging.audius.co",
186-
"https://discoveryprovider3.staging.audius.co",
187-
"https://discoveryprovider5.staging.audius.co",
188-
}
189-
}
190-
191-
app.Use(BalancerForward(upstreams))
192-
}
196+
app.Use(BalancerForward(config.PythonUpstreams))
193197

194198
// gracefully handle 404
195199
// (this won't get hit so long as above proxy is in place)
@@ -210,6 +214,7 @@ type ApiServer struct {
210214

211215
func (app *ApiServer) home(c *fiber.Ctx) error {
212216
return c.JSON(fiber.Map{
217+
"env": config.Cfg.Env,
213218
"started": app.started,
214219
"uptime": time.Since(app.started).Truncate(time.Second).String(),
215220
})

config/config.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,35 @@ import (
77
)
88

99
type Config struct {
10+
Env string
1011
DbUrl string
1112
DelegatePrivateKey string
1213
AxiomToken string
1314
AxiomDataset string
15+
PythonUpstreams []string
1416
}
1517

1618
var Cfg = Config{
19+
Env: os.Getenv("ENV"),
1720
DbUrl: os.Getenv("discoveryDbUrl"),
1821
DelegatePrivateKey: os.Getenv("delegatePrivateKey"),
1922
AxiomToken: os.Getenv("axiomToken"),
2023
AxiomDataset: os.Getenv("axiomDataset"),
2124
}
25+
26+
func init() {
27+
if os.Getenv("ENV") == "stage" {
28+
Cfg.PythonUpstreams = []string{
29+
"https://discoveryprovider.staging.audius.co",
30+
"https://discoveryprovider2.staging.audius.co",
31+
"https://discoveryprovider3.staging.audius.co",
32+
"https://discoveryprovider5.staging.audius.co",
33+
}
34+
} else {
35+
Cfg.PythonUpstreams = []string{
36+
"https://discoveryprovider.audius.co",
37+
"https://discoveryprovider2.audius.co",
38+
"https://discoveryprovider3.audius.co",
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)