Skip to content

Commit d676469

Browse files
authored
fix(app): fix CORS when fetching incentives (unionlabs#5201)
2 parents 8a71585 + c9d8b31 commit d676469

File tree

2 files changed

+53
-41
lines changed

2 files changed

+53
-41
lines changed

app2/src/lib/services/incentive.ts

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import { HttpClient, HttpClientResponse } from "@effect/platform"
1414
import { BigDecimal, Data, Effect, pipe, Schema } from "effect"
1515

16-
const REST_BASE_URL = import.meta.env.DEV ? "/api/union" : "https://rest.union.build"
16+
const REST_BASE_URL = "https://rest.union.build"
1717

1818
export class IncentiveError extends Data.TaggedError("IncentiveError")<{
1919
message: string
@@ -64,46 +64,70 @@ export const IncentiveResult = Schema.Struct({
6464
export type IncentiveResult = Schema.Schema.Type<typeof IncentiveResult>
6565

6666
const getInflation = pipe(
67-
HttpClient.get(`${REST_BASE_URL}/cosmos/mint/v1beta1/inflation`),
68-
Effect.flatMap(HttpClientResponse.schemaBodyJson(InflationResponse)),
69-
Effect.mapError((cause) =>
70-
new IncentiveError({
71-
message: "Failed to fetch inflation rate",
72-
cause,
73-
})
67+
HttpClient.HttpClient,
68+
Effect.map(HttpClient.withTracerDisabledWhen(() => true)),
69+
Effect.andThen((client) =>
70+
pipe(
71+
client.get(`${REST_BASE_URL}/cosmos/mint/v1beta1/inflation`),
72+
Effect.flatMap(HttpClientResponse.schemaBodyJson(InflationResponse)),
73+
Effect.mapError((cause) =>
74+
new IncentiveError({
75+
message: "Failed to fetch inflation rate",
76+
cause,
77+
})
78+
),
79+
)
7480
),
7581
)
7682

7783
const getStakingPool = pipe(
78-
HttpClient.get(`${REST_BASE_URL}/cosmos/staking/v1beta1/pool`),
79-
Effect.flatMap(HttpClientResponse.schemaBodyJson(StakingPoolResponse)),
80-
Effect.mapError((cause) =>
81-
new IncentiveError({
82-
message: "Failed to fetch staking pool",
83-
cause,
84-
})
84+
HttpClient.HttpClient,
85+
Effect.map(HttpClient.withTracerDisabledWhen(() => true)),
86+
Effect.andThen((client) =>
87+
pipe(
88+
client.get(`${REST_BASE_URL}/cosmos/staking/v1beta1/pool`),
89+
Effect.flatMap(HttpClientResponse.schemaBodyJson(StakingPoolResponse)),
90+
Effect.mapError((cause) =>
91+
new IncentiveError({
92+
message: "Failed to fetch staking pool",
93+
cause,
94+
})
95+
),
96+
)
8597
),
8698
)
8799

88100
const getDistributionParams = pipe(
89-
HttpClient.get(`${REST_BASE_URL}/cosmos/distribution/v1beta1/params`),
90-
Effect.flatMap(HttpClientResponse.schemaBodyJson(DistributionParamsResponse)),
91-
Effect.mapError((cause) =>
92-
new IncentiveError({
93-
message: "Failed to fetch distribution params",
94-
cause,
95-
})
101+
HttpClient.HttpClient,
102+
Effect.map(HttpClient.withTracerDisabledWhen(() => true)),
103+
Effect.andThen((client) =>
104+
pipe(
105+
client.get(`${REST_BASE_URL}/cosmos/distribution/v1beta1/params`),
106+
Effect.flatMap(HttpClientResponse.schemaBodyJson(DistributionParamsResponse)),
107+
Effect.mapError((cause) =>
108+
new IncentiveError({
109+
message: "Failed to fetch distribution params",
110+
cause,
111+
})
112+
),
113+
)
96114
),
97115
)
98116

99117
const getCirculatingSupply = pipe(
100-
HttpClient.get(`${REST_BASE_URL}/cosmos/bank/v1beta1/supply/by_denom?denom=au`),
101-
Effect.flatMap(HttpClientResponse.schemaBodyJson(CirculatingSupplyResponse)),
102-
Effect.mapError((cause) =>
103-
new IncentiveError({
104-
message: "Failed to fetch circulating supply",
105-
cause,
106-
})
118+
HttpClient.HttpClient,
119+
Effect.map(HttpClient.withTracerDisabledWhen(() => true)),
120+
Effect.andThen((client) =>
121+
pipe(
122+
client.get(`${REST_BASE_URL}/cosmos/bank/v1beta1/supply/by_denom?denom=au`),
123+
Effect.flatMap(HttpClientResponse.schemaBodyJson(CirculatingSupplyResponse)),
124+
Effect.mapError((cause) =>
125+
new IncentiveError({
126+
message: "Failed to fetch circulating supply",
127+
cause,
128+
})
129+
),
130+
)
107131
),
108132
)
109133

app2/vite.config.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@ export default defineConfig({
1212
build: { sourcemap: true },
1313
server: {
1414
allowedHosts: true,
15-
proxy: {
16-
"/api/union": {
17-
target: "https://rest.union.build",
18-
changeOrigin: true,
19-
rewrite: (path) => path.replace(/^\/api\/union/, ""),
20-
configure: (proxy) => {
21-
proxy.on("proxyReq", (proxyReq) => {
22-
proxyReq.setHeader("origin", "https://rest.union.build")
23-
})
24-
},
25-
},
26-
},
2715
},
2816
test: {
2917
workspace: [

0 commit comments

Comments
 (0)