| 1 | #!/usr/bin/env python3
|
|---|
| 2 |
|
|---|
| 3 | import connexion
|
|---|
| 4 | from flask_cors import CORS
|
|---|
| 5 | #from flask import render_template
|
|---|
| 6 | import flask
|
|---|
| 7 | from sqlalchemy import event
|
|---|
| 8 |
|
|---|
| 9 | from openapi_server import encoder
|
|---|
| 10 |
|
|---|
| 11 | from openapi_server.server_impl.database.Model import db, User, ApiKey, db_test_setup
|
|---|
| 12 |
|
|---|
| 13 | from openapi_server.server_impl.ValidatorWorkaround import ValidatorWorkaround
|
|---|
| 14 |
|
|---|
| 15 | app = connexion.App(__name__, specification_dir='./openapi/')
|
|---|
| 16 | application = app.app
|
|---|
| 17 | CORS(application)
|
|---|
| 18 |
|
|---|
| 19 | @application.before_first_request
|
|---|
| 20 | def create_database():
|
|---|
| 21 | @event.listens_for(db.engine, "connect")
|
|---|
| 22 | def load_spatialite(dbapi_conn, connection_record):
|
|---|
| 23 | if 'sqlite' in flask.current_app.config['SQLALCHEMY_DATABASE_URI']:
|
|---|
| 24 | # From https://geoalchemy-2.readthedocs.io/en/latest/spatialite_tutorial.html
|
|---|
| 25 | dbapi_conn.enable_load_extension(True)
|
|---|
| 26 | dbapi_conn.load_extension('/usr/local/lib64/mod_spatialite')
|
|---|
| 27 |
|
|---|
| 28 | db_test_setup()
|
|---|
| 29 |
|
|---|
| 30 | @application.route("/mapservice/")
|
|---|
| 31 | def index():
|
|---|
| 32 | return render_template('index.html')
|
|---|
| 33 |
|
|---|
| 34 | def main():
|
|---|
| 35 | application.json_encoder = encoder.JSONEncoder
|
|---|
| 36 | app.add_api('openapi.yaml', arguments={'title': 'GNUBoat Mapservice API'}, validate_responses=True, strict_validation=True, validator_map={'response': ValidatorWorkaround})
|
|---|
| 37 | application.config.from_object('openapi_server.server_impl.Config.DevelopmentConfig')
|
|---|
| 38 |
|
|---|
| 39 | db.init_app(application)
|
|---|
| 40 |
|
|---|
| 41 | app.run(port=8080)
|
|---|
| 42 |
|
|---|
| 43 | if __name__ == '__main__':
|
|---|
| 44 | main()
|
|---|