From 742439be9efc3ca45233b304ed6ab303cafc20cf Mon Sep 17 00:00:00 2001 From: Charles Le Maux Date: Sat, 29 Jun 2024 17:31:47 +0100 Subject: [PATCH] [+] New blueprint method [+] Allows subdomain filtering for routes [+] Allows routes scalability Signed-off-by: Charles Le Maux --- api_sender.html | 2 +- app.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/api_sender.html b/api_sender.html index e8cb9ad..a061ce8 100644 --- a/api_sender.html +++ b/api_sender.html @@ -100,7 +100,7 @@ document.addEventListener('DOMContentLoaded', () => { }); function sendRequest(endpoint, payload) { - return fetch(`http://192.168.1.94:3000/${endpoint}`, { + return fetch(`http://api.servii.fr:3000/${endpoint}`, { method: 'POST', headers: { 'Content-Type': 'application/json' diff --git a/app.py b/app.py index 730f5b2..70e10af 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,7 @@ import http import inspect -from flask import Flask, Response, jsonify, request +from flask import Blueprint, Flask, Response, jsonify, request from flask_cors import CORS import firebase_manager @@ -10,6 +10,7 @@ import generic_executor app = Flask(__name__) CORS(app) cors = CORS(app, origins=['*']) +apiBP = Blueprint('api', 'api', subdomain="api") def generic_response_maker(status_code: http.HTTPStatus, _message: str = None) -> tuple[Response, int]: @@ -90,7 +91,7 @@ route_handlers = { } -@app.route('/', methods=['POST']) +@apiBP.route('/', methods=['POST']) def dynamic_route_handler(path): if path not in route_handlers: return generic_response_maker(http.HTTPStatus.METHOD_NOT_ALLOWED) @@ -113,5 +114,6 @@ def dynamic_route_handler(path): if __name__ == '__main__': - ssl_context = ('/fullchain.pem', '/privkey.pem') - app.run(host='0.0.0.0', port=3000, debug=False) + ssl_context = ('/secrets/fullchain.pem', '/secrets/privkey.pem') + app.register_blueprint(apiBP) + app.run(host='0.0.0.0', port=3000, debug=False, ssl_context=ssl_context)