Skip to content
Snippets Groups Projects
server.py 1.98 KiB
Newer Older
  • Learn to ignore specific revisions
  • David Trattnig's avatar
    David Trattnig committed
    #
    # Aura Engine API (https://gitlab.servus.at/aura/engine-api)
    #
    # Copyright (C) 2020 - The Aura Engine Team.
    #
    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the GNU Affero General Public License as published by
    # the Free Software Foundation, either version 3 of the License, or
    # (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU Affero General Public License for more details.
    #
    # You should have received a copy of the GNU Affero General Public License
    # along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    
    David Trattnig's avatar
    David Trattnig committed
    import sys
    import os
    
    David Trattnig's avatar
    David Trattnig committed
    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
    
    
    import connexion
    from flask_sqlalchemy import SQLAlchemy
    from flask_marshmallow import Marshmallow
    
    from base.config import AuraConfig
    from base.logger import AuraLogger
    from rest import encoder
    from service import ApiService
    
    
    # App Initialization
    config = AuraConfig()
    logger = AuraLogger(config, "engine-api").logger
    
    def configure_flask(app):
        api.app.json_encoder = encoder.JSONEncoder
        app.config["SQLALCHEMY_DATABASE_URI"] = config.get_database_uri()
        app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
        app.config['ENV'] = "development"
        app.config['FLASK_ENV'] = "development"
        return app
    
    
    
    David Trattnig's avatar
    David Trattnig committed
    api = connexion.App(__name__, specification_dir='rest/swagger')
    
    api.add_api('swagger.yaml', arguments={'title': 'AURA Engine API'}, pythonic_params=True)
    app = configure_flask(api.app)
    db = SQLAlchemy(app)
    db.init_app(app)
    ma = Marshmallow(app)
    
    
    def startup():
        """
        Startup Server.
        """
        port = config.get("api_port")
        api.run(port=port)
    
    with app.app_context():
        """
        Initialize Server.
        """
        service = ApiService(config, logger)
        logger.info("API Service initialized.")
    
    
    
    if __name__ == '__main__':