Files
zeekay 2816591586 Initial exchange-proxy: caching reverse proxy for Uniswap APIs
- Proxies to 4 Uniswap API endpoints (CoreAPI, LiquidityAPI, GraphQL Gateway, ConversionAPI)
- Smart TTL-based caching (5s quotes, 30s pools, 5min token lists)
- Full CORS bypass for lux.exchange frontend
- In-memory cache with janitor cleanup
- Lightweight Go binary, Dockerfile included
2026-03-06 02:15:08 -08:00

52 lines
1.0 KiB
Go

package main
import (
"context"
"flag"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/luxfi/exchange-proxy/proxy"
)
func main() {
addr := flag.String("addr", ":8088", "listen address")
redisURL := flag.String("redis", "", "redis URL (optional, enables distributed cache)")
flag.Parse()
p := proxy.New(proxy.Config{
RedisURL: *redisURL,
})
mux := http.NewServeMux()
p.RegisterRoutes(mux)
srv := &http.Server{
Addr: *addr,
Handler: mux,
ReadTimeout: 30 * time.Second,
WriteTimeout: 60 * time.Second,
IdleTimeout: 120 * time.Second,
}
go func() {
log.Printf("exchange-proxy listening on %s", *addr)
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("listen: %v", err)
}
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
srv.Shutdown(ctx)
log.Println("exchange-proxy stopped")
}