-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.py
64 lines (53 loc) · 2.11 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from flask import Flask
from flask_restful import Api
from flask_cors import CORS
from resources.HomepageSearchCache import HomepageSearchCache
from resources.User import User
from resources.Login import Login
from resources.RefreshSession import RefreshSession
from resources.ApiKey import ApiKey
from resources.RequestResetPassword import RequestResetPassword
from resources.ResetPassword import ResetPassword
from resources.ResetTokenValidation import ResetTokenValidation
from resources.QuickSearch import QuickSearch
from resources.DataSources import (
DataSources,
DataSourcesNeedsIdentification,
DataSourceById,
DataSourcesMap,
)
from resources.Agencies import Agencies
from resources.Archives import Archives
from resources.SearchTokens import SearchTokens
from middleware.initialize_psycopg2_connection import initialize_psycopg2_connection
def add_resource(api, resource, endpoint, **kwargs):
api.add_resource(resource, endpoint, resource_class_kwargs=kwargs)
def create_app() -> Flask:
psycopg2_connection = initialize_psycopg2_connection()
app = Flask(__name__)
api = Api(app)
CORS(app)
resources = [
(User, "/user"),
(Login, "/login"),
(RefreshSession, "/refresh-session"),
(ApiKey, "/api_key"),
(RequestResetPassword, "/request-reset-password"),
(ResetPassword, "/reset-password"),
(ResetTokenValidation, "/reset-token-validation"),
(QuickSearch, "/quick-search/<search>/<location>"),
(Archives, "/archives"),
(DataSources, "/data-sources"),
(DataSourcesMap, "/data-sources-map"),
(DataSourcesNeedsIdentification, "/data-sources-needs-identification"),
(DataSourceById, "/data-sources-by-id/<data_source_id>"),
(Agencies, "/agencies/<page>"),
(SearchTokens, "/search-tokens"),
(HomepageSearchCache, "/homepage-search-cache"),
]
for resource, endpoint in resources:
add_resource(api, resource, endpoint, psycopg2_connection=psycopg2_connection)
return app
if __name__ == "__main__":
app = create_app()
app.run(debug=True, host="0.0.0.0")