from flask import Flask
from flask import request
from flask_json import FlaskJSON, json_response
app = Flask(__name__)
FlaskJSON(app)
@app.route("/")
def hello():
return json_response(200, headers=dict([ i for i in request.headers.items() ]))
@app.route("/forwardedfor")
def forwardedfor():
try:
return json_response(200, addresses="{}" .format(request.headers['X-Forwarded-For']))
except KeyError:
return json_response(200, error="No X-Forwarded-For header found")
Flask==0.12.2
flask_json
FROM python:3-alpine
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY app.py /usr/src/app
ENV FLASK_APP app.py
CMD ["flask", "run", "--host=0.0.0.0"]
docker build -t $imagetag .
docker run --rm -d -p5000:5000 $imagetag
Then point LB to it or have it proxied by Nginx/some other reverse proxy.