from flask import Blueprint, Response

from src.config import Configuration

from src.pages.api.v1 import v1api_bp
from src.pages.api.v2 import v2api_bp

api_bp = Blueprint("api", __name__, url_prefix="/api")

api_bp.register_blueprint(v1api_bp)
api_bp.register_blueprint(v2api_bp)

# set up cors handler for development
if (Configuration().development_mode):
    @api_bp.after_request
    def aug_api_response(response: Response):
        response.headers["Access-Control-Allow-Origin"] = Configuration().webserver["site"]
        response.headers["Access-Control-Allow-Headers"] = "Content-Type"
        response.headers["Access-Control-Allow-Credentials"] = "true"

        return response
