diff --git a/thegraph-proxy/.env.template b/thegraph-proxy/.env.template new file mode 100644 index 00000000..47983f76 --- /dev/null +++ b/thegraph-proxy/.env.template @@ -0,0 +1,2 @@ +THEGRAPH_GATEWAY_DOMAIN="gateway.thegraph.com" +THEGRAPH_API_KEY= \ No newline at end of file diff --git a/thegraph-proxy/README.md b/thegraph-proxy/README.md new file mode 100644 index 00000000..ca2c6908 --- /dev/null +++ b/thegraph-proxy/README.md @@ -0,0 +1,39 @@ +# TheGraph Proxy + +> ⚠️ Use this component for development purpose only + +Proxy server component relaying the calls to the decentralized thegraph network + +## Usage + +### prepare the `.env` file + +```sh +cp .env.template .env +``` + +fill in `THEGRAPH_API_KEY` in the generated [.env](.env) + +### launch the **thegraph-proxy** service + +```sh +docker compose up -d +``` + +The service is available at + +### use the service to query a subgraph + +example + +```js +curl --request POST \ + --url http://localhost:8080/subgraphs/id/2GCj8gzLCihsiEDq8cYvC5nUgK6VfwZ6hm3Wj8A3kcxz \ + --data '{"query":"query {\n\t_meta {\n\t\tdeployment\n\t\thasIndexingErrors\n\t\tblock {\n\t\t\tnumber\n\t\t}\n\t}\n}\n"}' +``` + +### stop the service + +```sh +docker compose down +``` diff --git a/thegraph-proxy/docker-compose.yml b/thegraph-proxy/docker-compose.yml new file mode 100644 index 00000000..702b70a2 --- /dev/null +++ b/thegraph-proxy/docker-compose.yml @@ -0,0 +1,12 @@ +services: + thegraph-proxy: + image: thegraph-proxy + build: + context: ./docker + dockerfile: Dockerfile + restart: unless-stopped + ports: + - '8080:80' + environment: + THEGRAPH_GATEWAY_DOMAIN: ${THEGRAPH_GATEWAY_DOMAIN} + THEGRAPH_API_KEY: ${THEGRAPH_API_KEY} diff --git a/thegraph-proxy/docker/Dockerfile b/thegraph-proxy/docker/Dockerfile new file mode 100644 index 00000000..7b7f511b --- /dev/null +++ b/thegraph-proxy/docker/Dockerfile @@ -0,0 +1,11 @@ +FROM nginx:alpine + +# Install envsubst (part of gettext) +RUN apk add --no-cache gettext + +# Copy config template and entrypoint script +COPY default.conf.template /etc/nginx/templates/default.conf.template +COPY entrypoint.sh /docker-entrypoint.d/entrypoint.sh + +# Make sure entrypoint is executable +RUN chmod +x /docker-entrypoint.d/entrypoint.sh \ No newline at end of file diff --git a/thegraph-proxy/docker/default.conf.template b/thegraph-proxy/docker/default.conf.template new file mode 100644 index 00000000..7d315f24 --- /dev/null +++ b/thegraph-proxy/docker/default.conf.template @@ -0,0 +1,13 @@ +server { + listen 80; + + location / { + proxy_pass https://${THEGRAPH_GATEWAY_DOMAIN}/api/${THEGRAPH_API_KEY}/; + + proxy_ssl_server_name on; + + proxy_set_header Host ${THEGRAPH_GATEWAY_DOMAIN}; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +} \ No newline at end of file diff --git a/thegraph-proxy/docker/entrypoint.sh b/thegraph-proxy/docker/entrypoint.sh new file mode 100644 index 00000000..f4abcf65 --- /dev/null +++ b/thegraph-proxy/docker/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# Replace env vars in template and save to nginx config dir +envsubst '$THEGRAPH_GATEWAY_DOMAIN $THEGRAPH_API_KEY' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf + +# Start nginx (inherited from base image entrypoint) +exec "$@"