initial commit
This commit is contained in:
18
drpc-beacon-proxy-holesky.yml
Normal file
18
drpc-beacon-proxy-holesky.yml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
services:
|
||||||
|
beacon-proxy:
|
||||||
|
build: ./drpc-beacon-proxy/
|
||||||
|
expose:
|
||||||
|
- "80:80"
|
||||||
|
environment:
|
||||||
|
DKEY: "${DRPC_API_KEY}"
|
||||||
|
NETWORK: "holesky"
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
- "traefik.http.middlewares.drpc-beacon-proxy-holesky-stripprefix.stripprefix.prefixes=/drpc-beacon-proxy-holesky"
|
||||||
|
- "traefik.http.services.drpc-beacon-proxy-holesky.loadbalancer.server.port=80"
|
||||||
|
- "traefik.http.routers.drpc-beacon-proxy-holesky.entrypoints=websecure"
|
||||||
|
- "traefik.http.routers.drpc-beacon-proxy-holesky.tls.certresolver=myresolver"
|
||||||
|
- "traefik.http.routers.drpc-beacon-proxy-holesky.rule=Host(`$DOMAIN`) && PathPrefix(`/drpc-beacon-proxy-holesky`)"
|
||||||
|
- "traefik.http.routers.drpc-beacon-proxy-holesky.middlewares=drpc-beacon-proxy-holesky-stripprefix, ipwhitelist"
|
||||||
|
networks:
|
||||||
|
- chains
|
||||||
9
drpc-beacon-proxy/Dockerfile
Normal file
9
drpc-beacon-proxy/Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
FROM python:3.11-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN pip install flask requests
|
||||||
|
|
||||||
|
COPY proxy.py /app/
|
||||||
|
|
||||||
|
CMD ["python", "proxy.py"]
|
||||||
33
drpc-beacon-proxy/proxy.py
Normal file
33
drpc-beacon-proxy/proxy.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import os
|
||||||
|
from flask import Flask, request, Response
|
||||||
|
import requests
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
# Read config from environment variables
|
||||||
|
DKEY = os.getenv("DKEY", "your-default-dkey")
|
||||||
|
NETWORK = os.getenv("NETWORK", "holesky")
|
||||||
|
TARGET_URL = f"https://lb.drpc.org/rest/eth-beacon-chain-{NETWORK}"
|
||||||
|
|
||||||
|
@app.route('/<path:subpath>', methods=["GET", "POST", "PUT", "DELETE", "PATCH"])
|
||||||
|
def proxy(subpath):
|
||||||
|
url = f"{TARGET_URL}/{subpath}"
|
||||||
|
|
||||||
|
# Forward query params and add the dkey
|
||||||
|
params = request.args.to_dict()
|
||||||
|
params["dkey"] = DKEY
|
||||||
|
|
||||||
|
# Forward headers (except Host) and body
|
||||||
|
headers = {k: v for k, v in request.headers if k.lower() != "host"}
|
||||||
|
data = request.get_data() if request.method in ["POST", "PUT", "PATCH"] else None
|
||||||
|
|
||||||
|
# Forward the request
|
||||||
|
resp = requests.request(
|
||||||
|
method=request.method, url=url, params=params, headers=headers, data=data
|
||||||
|
)
|
||||||
|
|
||||||
|
# Return response with original status and headers
|
||||||
|
return Response(resp.content, resp.status_code, resp.headers.items())
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run(host="0.0.0.0", port=80)
|
||||||
Reference in New Issue
Block a user