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
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ENV PYTHONUNBUFFERED=1
ENV FLASK_ENV=production
ENV LOG_LEVEL=info

CMD ["sh", "-c", "gunicorn -b 0.0.0.0:4499 turnify:app \
--log-level $(echo $LOG_LEVEL | tr '[:upper:]' '[:lower:]') \
--access-logfile ${GUNICORN_ACCESS_LOG:-'-'} \
--error-logfile ${GUNICORN_ERROR_LOG:-'-'}"]
COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh

CMD ["/app/entrypoint.sh"]
4 changes: 2 additions & 2 deletions app/turnify.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@app.before_request
def log_request():
app.logger.debug(f"Received {request.method} request to {request.path} from {request.remote_addr}")

@app.route('/<path:subpath>/voip/turnServer', methods=['GET'])
def proxy_request(subpath):
app.logger.debug(f"Handling {request.method} request for {request.path}")
Expand Down Expand Up @@ -126,7 +126,7 @@ def generate():
status=response.status_code,
headers={key: value for key, value in response.headers.items() if key.lower() != 'transfer-encoding'}
)

except requests.exceptions.RequestException as e:
app.logger.error(f"{ip_addr} -- Error forwarding request to Synapse: {e}")
return jsonify({"error": "Failed to connect to Synapse"}), 502
Expand Down
37 changes: 37 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

python3 - <<'EOF'
import socket, sys
try:
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(("::", 4499))
s.listen(1)

test = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
test.connect(("127.0.0.1", 4499))
sys.exit(0)
except Exception:
sys.exit(1)
finally:
test.close()
except Exception:
sys.exit(1)
finally:
s.close()
EOF

if [ $? -eq 0 ]; then
echo "Use IPv4-mapped IPv6"
exec gunicorn -w 4 -b [::]:4499 turnify:app \
--log-level "$(echo $LOG_LEVEL | tr '[:upper:]' '[:lower:]')" \
--access-logfile "${GUNICORN_ACCESS_LOG:--}" \
--error-logfile "${GUNICORN_ERROR_LOG:--}"
else
echo "Use manual IPv4 and IPv6 binding"
exec gunicorn -w 4 -b 0.0.0.0:4499 -b [::]:4499 turnify:app \
--log-level "$(echo $LOG_LEVEL | tr '[:upper:]' '[:lower:]')" \
--access-logfile "${GUNICORN_ACCESS_LOG:--}" \
--error-logfile "${GUNICORN_ERROR_LOG:--}"
fi