Skip to content

Commit b766840

Browse files
committed
Mount v2 of the application
1 parent e7be141 commit b766840

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

app/__init__.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,4 @@
1-
from flask import Flask
2-
from flask_cors import CORS
3-
41
# See PEP396.
52
__version__ = '2.0'
63

7-
def create_app():
8-
"""
9-
Construct the core application.
10-
"""
11-
# Create flask app with CORS enabled.
12-
app = Flask(__name__)
13-
CORS(app)
14-
15-
# Set app config from settings.
16-
app.config.from_pyfile('config/settings.py');
17-
18-
with app.app_context():
19-
# Import routes.
20-
from . import routes
21-
22-
# Register api endpoints.
23-
app.register_blueprint(routes.api_v1)
24-
app.register_blueprint(routes.api_v2)
25-
26-
# Return created app.
27-
return app
4+
from .core import create_app

app/core.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from flask import Flask
2+
from flask_cors import CORS
3+
4+
def create_app():
5+
"""
6+
Construct the core application.
7+
"""
8+
# Create flask app with CORS enabled.
9+
app = Flask(__name__)
10+
CORS(app)
11+
12+
# Set app config from settings.
13+
app.config.from_pyfile('config/settings.py');
14+
15+
with app.app_context():
16+
# Import routes.
17+
from . import routes
18+
19+
# Register api endpoints.
20+
app.register_blueprint(routes.api_v1)
21+
app.register_blueprint(routes.api_v2)
22+
23+
# Return created app.
24+
return app

app/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import fastapi
1111
import pydantic
1212
import uvicorn
13+
from fastapi.middleware.wsgi import WSGIMiddleware
1314

1415
from .data import data_source
16+
from .core import create_app
1517

1618
# #################################
1719
# Models
@@ -153,6 +155,8 @@ def get_all_locations(
153155
def get_location_by_id(request: fastapi.Request, id: int, timelines: int = 1):
154156
return {"location": request.state.source.get(id).serialize(timelines)}
155157

158+
# mount the existing Flask app to /v2
159+
APP.mount("/v2", WSGIMiddleware(create_app()))
156160

157161
if __name__ == "__main__":
158162
uvicorn.run(

0 commit comments

Comments
 (0)