Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions api/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
import { serve } from 'bun'

const ENSO_API_BASE = 'https://api.enso.finance'
const YVUSD_APR_SERVICE_API = (
process.env.YVUSD_APR_SERVICE_API || 'https://yearn-yvusd-apr-service.vercel.app/api/aprs'
).replace(/\/$/, '')

async function handleYvUsdAprs(req: Request): Promise<Response> {
if (req.method !== 'GET') {
return Response.json({ error: 'Method not allowed' }, { status: 405 })
}

const requestUrl = new URL(req.url)
const upstreamUrl = new URL(YVUSD_APR_SERVICE_API)
requestUrl.searchParams.forEach((value, key) => {
upstreamUrl.searchParams.set(key, value)
})

try {
const response = await fetch(upstreamUrl.toString(), {
headers: {
Accept: 'application/json'
}
})

if (!response.ok) {
const details = await response.text()
return Response.json(
{ error: 'yvUSD APR upstream error', status: response.status, details },
{ status: response.status }
)
}

const data = await response.json()
return Response.json(data, {
headers: {
'Cache-Control': 'public, s-maxage=30, stale-while-revalidate=120'
}
})
} catch (error) {
console.error('Error proxying yvUSD APR request:', error)
return Response.json({ error: 'Internal server error' }, { status: 500 })
}
}

function handleEnsoStatus(): Response {
const apiKey = process.env.ENSO_API_KEY
Expand Down Expand Up @@ -133,6 +174,10 @@ serve({
return handleEnsoRoute(req)
}

if (url.pathname === '/api/yvusd/aprs') {
return handleYvUsdAprs(req)
}

return new Response('Not found', { status: 404 })
},
port: 3001
Expand Down
42 changes: 42 additions & 0 deletions api/yvusd/aprs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { VercelRequest, VercelResponse } from '@vercel/node'

const YVUSD_APR_SERVICE_API = (
process.env.YVUSD_APR_SERVICE_API || 'https://yearn-yvusd-apr-service.vercel.app/api/aprs'
).replace(/\/$/, '')

export default async function handler(req: VercelRequest, res: VercelResponse) {
if (req.method !== 'GET') {
return res.status(405).json({ error: 'Method not allowed' })
}

try {
const upstreamUrl = new URL(YVUSD_APR_SERVICE_API)
Object.entries(req.query).forEach(([key, value]) => {
if (typeof value === 'string') {
upstreamUrl.searchParams.set(key, value)
}
})

const response = await fetch(upstreamUrl.toString(), {
headers: {
Accept: 'application/json'
}
})

if (!response.ok) {
const details = await response.text()
return res.status(response.status).json({
error: 'yvUSD APR upstream error',
status: response.status,
details
})
}

const data = await response.json()
res.setHeader('Cache-Control', 'public, s-maxage=30, stale-while-revalidate=120')
return res.status(200).json(data)
} catch (error) {
console.error('Error proxying yvUSD APR request:', error)
return res.status(500).json({ error: 'Internal server error' })
}
}
1 change: 1 addition & 0 deletions public/lock-closed-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/lock-closed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/lock-open-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/lock-open-white2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/lock-open.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/yvUSD-C-seal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/yvUSD-C.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/yvUSD-seal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/yvUSD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/yvusd-banner-bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading