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