Index: src/mapservice/codegen/templates/__init__.mustache
===================================================================
--- src/mapservice/codegen/templates/__init__.mustache	(revision bd0cb38e900c943ced620072feb0270b34682037)
+++ src/mapservice/codegen/templates/__init__.mustache	(revision a88607b183ce311a18e1c7fcbaa80e52cfd4c12a)
@@ -1,8 +1,10 @@
-import connexion
-from flask_cors import CORS
-from flask_mail import Mail
+#import connexion
+#from flask_cors import CORS
+#from flask_mail import Mail
+#from celery import Celery
 
-app = connexion.App(__name__, specification_dir='./openapi/')
-application = app.app
-CORS(application)
-mail = Mail()
+#app = connexion.App(__name__, specification_dir='./openapi/')
+#application = app.app
+#CORS(application)
+#mail = Mail()
+#celery = Celery(application.name)
Index: src/mapservice/codegen/templates/__main__.mustache
===================================================================
--- src/mapservice/codegen/templates/__main__.mustache	(revision bd0cb38e900c943ced620072feb0270b34682037)
+++ src/mapservice/codegen/templates/__main__.mustache	(revision a88607b183ce311a18e1c7fcbaa80e52cfd4c12a)
@@ -6,38 +6,9 @@
 {{/supportPython2}}
 
-import flask
-from sqlalchemy import event
+from {{packageName}}.server_impl import app, application, mail, celery, setup_app
 
-from {{packageName}} import encoder, app, application, mail
-from {{packageName}}.server_impl.database.Model import db, User, ApiKey, db_setup, db_test_setup
-from {{packageName}}.server_impl.ValidatorWorkaround import ValidatorWorkaround
-
-@application.before_first_request
-def create_database():
-	@event.listens_for(db.engine, "connect")
-	def load_spatialite(dbapi_conn, connection_record):
-		if 'sqlite' in flask.current_app.config['SQLALCHEMY_DATABASE_URI']:
-			# From https://geoalchemy-2.readthedocs.io/en/latest/spatialite_tutorial.html
-			dbapi_conn.enable_load_extension(True)
-			dbapi_conn.load_extension('/usr/local/lib64/mod_spatialite')
-
-	if flask.current_app.config['CREATE_TEST_DATABASE'] == True:
-		db_test_setup()
-	else:
-		db_setup()
-
-@application.route("/mapservice/")
-def index():
-	return render_template('index.html')
-	
 def main():
-	application.json_encoder = encoder.JSONEncoder
-	app.add_api('openapi.yaml', arguments={'title': '{{appName}}'}, validate_responses=True, strict_validation=True, validator_map={'response': ValidatorWorkaround})
-	application.config.from_object('{{packageName}}.server_impl.Config.DevelopmentConfig')
-
-	db.init_app(application)
-	mail.init_app(application)
-
-	app.run(port={{serverPort}})
+	setup_app('{{appName}}', 'DevelopmentConfig')
+	app.run(host=application.config.get("HOST", "localhost"), port=application.config.get("PORT", {{serverPort}}))
 
 if __name__ == '__main__':
Index: src/mapservice/codegen/templates/requirements.mustache
===================================================================
--- src/mapservice/codegen/templates/requirements.mustache	(revision bd0cb38e900c943ced620072feb0270b34682037)
+++ src/mapservice/codegen/templates/requirements.mustache	(revision a88607b183ce311a18e1c7fcbaa80e52cfd4c12a)
@@ -13,3 +13,4 @@
 sqlalchemy_utc
 sqlalchemy-utils
+celery
 gnuboat_common
