Skip to content

Commit a07c3c0

Browse files
committed
Initial commit
1 parent c8f219b commit a07c3c0

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Dockerfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM python:3.11-alpine
2+
3+
WORKDIR /app
4+
COPY app.py /app
5+
RUN pip install --no-cache-dir flask gunicorn
6+
EXPOSE 5000
7+
8+
ENV FLASK_ENV=production
9+
ENV FLASK_APP=app.py
10+
ENV TOKEN="default"
11+
12+
CMD ["gunicorn", "--workers", "1", "--bind", "0.0.0.0:5000", "app:app"]

app.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from flask import Flask, request, jsonify
2+
import os
3+
4+
app = Flask(__name__)
5+
6+
# Load token from environment variable
7+
TOKEN = os.environ['TOKEN']
8+
9+
@app.route('/validate', methods=['GET', 'POST'])
10+
def validate_token():
11+
auth_header = request.headers.get('Authorization')
12+
if auth_header and auth_header.startswith('Bearer '):
13+
token_from_header = auth_header[7:]
14+
if token_from_header == TOKEN:
15+
return jsonify({'message': 'Token is valid'}), 200
16+
else:
17+
return jsonify({'message': 'Token is invalid'}), 401
18+
else:
19+
return jsonify({'message': 'No Bearer token provided'}), 400
20+
21+
if __name__ == '__main__':
22+
app.run(host='0.0.0.0', port=5000, debug=True)

0 commit comments

Comments
 (0)