1010import gevent
1111from marshmallow import fields
1212from sqlalchemy .schema import MetaData
13+ from sqlalchemy import text
1314from flask_sqlalchemy import SQLAlchemy
1415from flask_marshmallow import Marshmallow
1516from flask import (
2728from flask_wtf .csrf import generate_csrf , CSRFProtect
2829from flask_migrate import Migrate
2930from flask_mail import Mail
30- from connexion .apps .flask_app import FlaskJSONEncoder
3131from flask_wtf import FlaskForm
3232from wtforms import StringField
3333from pathlib import Path
3737from werkzeug .exceptions import HTTPException
3838from typing import List , Dict , Optional , Tuple
3939
40- from .sync .utils import get_blacklisted_dirs , get_blacklisted_files
4140from .config import Configuration
4241from .commands import add_commands as server_commands
4342
@@ -139,7 +138,6 @@ def create_simple_app() -> Flask:
139138 app = connexion .FlaskApp (__name__ , specification_dir = os .path .join (this_dir ))
140139 flask_app = app .app
141140
142- flask_app .json_encoder = FlaskJSONEncoder
143141 flask_app .config .from_object (Configuration )
144142 db .init_app (flask_app )
145143 ma .init_app (flask_app )
@@ -155,54 +153,36 @@ def create_simple_app() -> Flask:
155153def create_app (public_keys : List [str ] = None ) -> Flask :
156154 """Factory function to create Flask app instance"""
157155 from itsdangerous import BadTimeSignature , BadSignature
158- from .auth import auth_required , decode_token
159- from .auth .models import User
160156
161- # from .celery import celery
162- from .sync .db_events import register_events
163- from .sync .workspace import GlobalWorkspaceHandler
164- from .sync .config import Configuration as SyncConfig
165- from .sync .commands import add_commands
166- from .auth import register as register_auth
157+ from .auth import auth_required , decode_token , register as register_auth
158+ from .auth .models import User
159+ from .sync .app import register as register_sync
167160 from .sync .project_handler import ProjectHandler
161+ from .sync .utils import get_blacklisted_dirs , get_blacklisted_files
162+ from .sync .workspace import GlobalWorkspaceHandler
168163
169164 app = create_simple_app ().connexion_app
170165
171- app .add_api (
172- "sync/public_api.yaml" ,
173- arguments = {"title" : "Mergin" },
174- options = {"swagger_ui" : Configuration .SWAGGER_UI },
175- validate_responses = True ,
176- )
177- app .add_api (
178- "sync/public_api_v2.yaml" ,
179- arguments = {"title" : "Mergin" },
180- options = {"swagger_ui" : Configuration .SWAGGER_UI },
181- validate_responses = True ,
182- )
183- app .add_api (
184- "sync/private_api.yaml" ,
185- base_path = "/app" ,
186- arguments = {"title" : "Mergin" },
187- options = {"swagger_ui" : False , "serve_spec" : False },
188- validate_responses = True ,
189- )
190166 app .add_api (
191167 "api.yaml" ,
192168 arguments = {"title" : "Mergin" },
193169 options = {"swagger_ui" : False , "serve_spec" : False },
194170 validate_responses = True ,
195171 )
172+ app .app .blueprints ["/" ].name = "main"
173+ app .app .blueprints ["main" ] = app .app .blueprints .pop ("/" )
196174
197- app . app . config . from_object ( SyncConfig )
198- app .app . connexion_app = app
175+ # register sync module
176+ register_sync ( app .app )
199177
178+ # initialize extensions
200179 mail .init_app (app .app )
201- app .mail = mail
202180 csrf .init_app (app .app )
203181 login_manager .init_app (app .app )
182+
204183 # register auth blueprint
205184 register_auth (app .app )
185+
206186 server_commands (app .app )
207187
208188 # adjust login manager
@@ -228,8 +208,6 @@ def load_user_from_header(header_val): # pylint: disable=W0613,W0612
228208 except (BadSignature , BadTimeSignature , KeyError ):
229209 pass
230210
231- # csrf = app.app.extensions['csrf']
232-
233211 @app .app .before_request
234212 def check_maintenance ():
235213 allowed_endpoints = ["/project/by_names" , "/auth/login" , "/alive" ]
@@ -275,9 +253,6 @@ def get_startup_data():
275253 }
276254 return data
277255
278- # update celery config with flask app config
279- # celery.conf.update(app.app.config)
280-
281256 @app .route ("/alive" , methods = ["POST" ])
282257 @csrf .exempt
283258 def alive (): # pylint: disable=E0722
@@ -287,7 +262,7 @@ def alive(): # pylint: disable=E0722
287262 start_time = time .time ()
288263 try :
289264 with db .engine .connect () as con :
290- rs = con .execute ("SELECT 2 * 2" )
265+ rs = con .execute (text ( "SELECT 2 * 2" ) )
291266 assert rs .fetchone ()[0 ] == 4
292267 except :
293268 """Although bad form, we have deliberate left this except broad. When we have an uncaught exception in
@@ -388,7 +363,6 @@ def init(): # pylint: disable=W0612
388363 response .headers .set ("X-CSRF-Token" , generate_csrf ())
389364 return response
390365
391- register_events ()
392366 application = app .app
393367
394368 @application .errorhandler (Exception )
@@ -467,8 +441,6 @@ def config():
467441 cfg ["build_hash" ] = application .config ["BUILD_HASH" ]
468442 return jsonify (cfg ), 200
469443
470- # append project commands (from default sync module)
471- add_commands (application )
472444 return application
473445
474446
0 commit comments