-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
64 lines (50 loc) · 1.54 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
from flask import Flask, request
from flask_restful import Api
from flask_jwt_extended import JWTManager
from dotenv import load_dotenv
from config.logger import configure_logger
from routes.hello_world import HelloWorld
from routes.authenticate import Authenticate
from routes.content_portal import ContentPortal
## ------ BASIC CONFIG ------ ##
load_dotenv()
# define app and api
app = Flask(__name__)
# configure JWT
app.config["JWT_SECRET_KEY"] = os.getenv("JWT_SECRET_KEY")
JWT = JWTManager(app)
# set api
api = Api(app)
## ------ LOGGING ------ ##
logger = configure_logger()
@app.before_request
def log_request_info():
logger.info(
f"Request received - Method: {request.method}, Path: {request.path}, User: {request.remote_addr}"
)
@app.after_request
def log_response_info(response):
response_data = response.get_json()
logger.info(
f"Response sent - Status: {response.status_code}"
)
if response_data is not None:
if "message" in response_data:
logger.info(
f"Response message: {response_data['message']}"
)
if "user" in response_data:
logger.info(
f"User: {response_data['user']}"
)
return response
## ------ ENDPOINTS ------ ##
api.add_resource(HelloWorld, "/")
api.add_resource(Authenticate, "/authenticate")
api.add_resource(ContentPortal, "/content_portal")
## ------ RUN APPLICATION ------ ##
if __name__ == "__main__":
app.run(host="0.0.0.0",
port=8080,
debug=True)