Skip to content
Open
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
1 change: 0 additions & 1 deletion common.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listen 0.0.0.0:${PORT};
resolver ${DNS} valid=5s;
proxy_http_version 1.1;
proxy_ssl_server_name on;
server_tokens off;
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "2"

services:
proxy:
build:
context: .
restart: always
ports:
- 8080:80
environment:
ENDPOINT: https://pro-api.coingecko.com/api/v3/
AUTHORIZATION_HEADER: x-cg-pro-api-key
AUTHORIZATION_HEADER_VALUE: test
45 changes: 7 additions & 38 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,49 +1,18 @@
#!/bin/bash
set -eu

export DNS="${DNS}"
export PORT="${RPC_PORT:-80}"
export WS="${WS:-"NO"}"
export STATUS_METHOD="${STATUS_METHOD:-net_version}"
export AUTHORIZATION_HEADER="${AUTHORIZATION_HEADER:-}"
export AUTHORIZATION_HEADER_VALUE="${AUTHORIZATION_HEADER_VALUE:-}"
export AUTHORIZATION=""

if [[ ! -z "${WS_ENDPOINT:-}" ]]; then
export WS="YES"
if [[ ! -z "${AUTHORIZATION_HEADER:-}" ]] && [[ ! -z "${AUTHORIZATION_HEADER_VALUE:-}" ]]; then
AUTHORIZATION=$(echo -n "proxy_set_header ${AUTHORIZATION_HEADER} ${AUTHORIZATION_HEADER_VALUE};")
fi

if [[ ! -z "${ENDPOINT:-}" ]]; then
export RPC_ENDPOINT="${ENDPOINT}"
export WS_ENDPOINT="${ENDPOINT}"
else
export RPC_ENDPOINT="${RPC_ENDPOINT}"
export WS_ENDPOINT="${WS_ENDPOINT}"
fi

if [[ -z "${USERNAME:-}" || -z "${PASSWORD:-}" ]] && [[ "$WS" = "YES" ]]; then
# WS and no auth
file=/tmp/rpc.ws.conf.template
#envsubst '${AUTHORIZATION_HEADER}' < /tmp/rpc.ws.conf.template > /etc/nginx/conf.d/default.conf
elif [[ -z "${USERNAME:-}" || -z "${PASSWORD:-}" ]]; then
# no ws and no auth
file=/tmp/rpc.conf.template
#envsubst '${AUTHORIZATION_HEADER}' < /tmp/rpc.conf.template > /etc/nginx/conf.d/default.conf
else
AUTHORIZATION=$(echo -n "${USERNAME}:${PASSWORD}" | base64 | tr -d \\n)
AUTHORIZATION_HEADER=$(echo -n "proxy_set_header Authorization \"Basic ${AUTHORIZATION}\";")
if [[ "$WS" = "YES" ]]; then
# ws and auth
file=/tmp/rpc.ws.conf.template
#envsubst '${AUTHORIZATION_HEADER}' < /tmp/rpc.ws.conf.template > /etc/nginx/conf.d/default.conf
else
# no ws and auth
file=/tmp/rpc.conf.template
#envsubst '${AUTHORIZATION_HEADER}' < /tmp/rpc.conf.template > /etc/nginx/conf.d/default.conf
fi
fi
envsubst '${AUTHORIZATION_HEADER}' < $file > /etc/nginx/conf.d/default.conf
envsubst '${DNS} ${PORT}' < /tmp/common.template > /etc/nginx/conf.d/common.template
mv /tmp/rpc.conf.template /etc/nginx/conf.d/default.conf
envsubst '${PORT}' < /tmp/common.template > /etc/nginx/conf.d/common.template
envsubst '${STATUS_METHOD}' < /tmp/status.template > /etc/nginx/conf.d/status.template
envsubst '${RPC_ENDPOINT}' < /tmp/rpc.template > /etc/nginx/conf.d/rpc.template
envsubst '${WS_ENDPOINT}' < /tmp/ws.template > /etc/nginx/conf.d/ws.template
envsubst '${AUTHORIZATION} ${ENDPOINT}' < /tmp/rpc.template > /etc/nginx/conf.d/rpc.template

exec "$@"
2 changes: 0 additions & 2 deletions rpc.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ server {

include /etc/nginx/conf.d/common.template;

${AUTHORIZATION_HEADER}

include /etc/nginx/conf.d/rpc.template;

include /etc/nginx/conf.d/status.template;
Expand Down
3 changes: 2 additions & 1 deletion rpc.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
location / {
proxy_pass ${RPC_ENDPOINT};
proxy_pass ${ENDPOINT};
proxy_set_header Connection "";
${AUTHORIZATION}
}
12 changes: 0 additions & 12 deletions rpc.ws.conf.template

This file was deleted.

5 changes: 0 additions & 5 deletions ws.template

This file was deleted.