diff --git a/common.template b/common.template index ced847e..f2ab52d 100644 --- a/common.template +++ b/common.template @@ -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; diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..2e385a5 --- /dev/null +++ b/docker-compose.yaml @@ -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 diff --git a/entrypoint.sh b/entrypoint.sh index 99cc1fd..35bb2a8 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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 "$@" \ No newline at end of file diff --git a/rpc.conf.template b/rpc.conf.template index 20521fd..bcf9258 100644 --- a/rpc.conf.template +++ b/rpc.conf.template @@ -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; diff --git a/rpc.template b/rpc.template index 4ab53bc..570c0b2 100644 --- a/rpc.template +++ b/rpc.template @@ -1,4 +1,5 @@ location / { - proxy_pass ${RPC_ENDPOINT}; + proxy_pass ${ENDPOINT}; proxy_set_header Connection ""; + ${AUTHORIZATION} } \ No newline at end of file diff --git a/rpc.ws.conf.template b/rpc.ws.conf.template deleted file mode 100644 index f189b93..0000000 --- a/rpc.ws.conf.template +++ /dev/null @@ -1,12 +0,0 @@ -server { - include /etc/nginx/conf.d/common.template; - - ${AUTHORIZATION_HEADER} - - include /etc/nginx/conf.d/rpc.template; - - include /etc/nginx/conf.d/ws.template; - - include /etc/nginx/conf.d/status.template; - -} diff --git a/ws.template b/ws.template deleted file mode 100644 index 8f7b70d..0000000 --- a/ws.template +++ /dev/null @@ -1,5 +0,0 @@ -location /ws { - proxy_pass ${WS_ENDPOINT}; - proxy_set_header Connection "upgrade"; - proxy_set_header Upgrade $http_upgrade; -} \ No newline at end of file