#!/bin/sh

if [ -n "$PROXY_URL" ]; then
    export HOSTNAME="127.0.0.1"
    protocol=$(echo "$PROXY_URL" | cut -d: -f1)
    host=$(echo "$PROXY_URL" | cut -d/ -f3 | cut -d: -f1)
    port=$(echo "$PROXY_URL" | cut -d: -f3)
    conf=/etc/proxychains.conf
    cat /dev/null > $conf
    {
        echo "strict_chain"
        echo "proxy_dns"
        echo "remote_dns_subnet 224"
        echo "tcp_read_time_out 15000"
        echo "tcp_connect_time_out 8000"
        echo "localnet 127.0.0.0/255.0.0.0"
        echo "localnet ::1/128"
        echo "[ProxyList]"
    } >> $conf
    echo "$protocol $host $port" >> $conf
    cat /etc/proxychains.conf
    proxychains -f $conf node server.js
else
    node server.js
fi
