Skip to content

Commit

Permalink
Fri Oct 11 13:18:07 CEST 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalii Dubovoy committed Oct 11, 2024
1 parent a65efd1 commit 32bbfbb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

@app.route('/app', methods=['GET'])
def get_client_ip():
# Get the client's IP address
client_ip = request.remote_addr
# Return the response with the client's IP
# Check if the request has the 'X-Forwarded-For' header
if 'X-Forwarded-For' in request.headers:
# Get the first IP in the 'X-Forwarded-For' header, which is the client's real IP
client_ip = request.headers['X-Forwarded-For'].split(',')[0].strip()
else:
# Fall back to the direct remote address if 'X-Forwarded-For' is not present
client_ip = request.remote_addr

return f"Hello there, your IP is - {client_ip}"

@app.route('/health', methods=['GET'])
def health_check():
# Simply return a 200 OK status
return 'OK', 200

if __name__ == '__main__':
Expand Down

0 comments on commit 32bbfbb

Please sign in to comment.