Commit 82448d49 authored by Robin's avatar Robin

adapted routing for more flexibility

parent 5ee6d1e2
......@@ -9,8 +9,7 @@ from flask_caching import Cache
from werkzeug.exceptions import HTTPException
from src.api import config
from src.api.routes import validation_v2_entities, historic_validation_v2_entities, validation_ld_entities, \
historic_validation_ld_entities
from src.api.routes import validation_router, historic_validation_router
from src.api.server_utils import ValidationErrorResponse, random_id, parse_model
from src.logger import FORMATTER
......@@ -23,10 +22,9 @@ def create_app():
# configure app and routes
app = Flask(__name__, instance_relative_config=True)
app.register_blueprint(validation_v2_entities)
app.register_blueprint(historic_validation_v2_entities)
app.register_blueprint(validation_ld_entities)
app.register_blueprint(historic_validation_ld_entities)
app.register_blueprint(validation_router)
app.register_blueprint(historic_validation_router)
if develop:
from src.api import develop_config
......@@ -92,15 +90,4 @@ def create_app():
""" For developing purposes: Executed after every request, regardless of any occurring error. """
app.logger.debug('Teardown request')
@app.before_first_request
def load_validation_context():
# """ Initially loads all URL resources to cache `APP_CACHE`. """
# request.custom_id = 'before_first_request'
# TODO TBD maybe remove this condition
# if not app.config["READ_SPECS_FROM_DISK"] and not app.config["READ_BLUEPRINTS_FROM_DISK"]:
# try:
# load_url_resources(model_name='*')
# except ValidationException:
pass
return app
This diff is collapsed.
......@@ -460,22 +460,22 @@ def load_url_resources(model_name: str = '*'):
current_app.logger.info(f'<<{__name__}>> Url resources for `{model_name}` loaded to cache.')
def send_to_platform(forward_url: str):
def send_to_platform(forward_uri: str):
"""
Redirects the request context (body, header) to the IOT platform.
Args:
forward_url: Full uri of the platform (including host, port, path, params, ...)
forward_uri: Full uri of the platform (including host, port, path, params, ...)
Raises:
ValidationErrorResponse: Response for any occurring HTTPException
"""
current_app.logger.info(f'<<{__name__}>> Trying to forward request to {forward_url}')
current_app.logger.info(f'<<{__name__}>> Trying to forward request to {forward_uri}')
try:
# redirect to preserve context of request (header, body, ...)
return redirect(f'http://{forward_url}', code=307)
return redirect(f'http://{forward_uri}', code=307)
except HTTPException:
raise ValidationErrorResponse(msg=f'Redirect for `http://{forward_url}` failed.',
raise ValidationErrorResponse(msg=f'Redirect for `http://{forward_uri}` failed.',
module=__name__)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment