-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
45 lines (36 loc) · 1.47 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
import os
import secrets
from datetime import timedelta
from dotenv import load_dotenv
from flask import Flask
from flask_cors import CORS
from flask_jwt_extended import JWTManager
from database import mongo
from routes.authentication import authentication_router
from routes.files import files_router
from routes.instances import instances_router
from routes.mapping import mapping_router
from routes.ontology import ontology_router
from routes.users import users_router
def create_app():
load_dotenv()
app = Flask(__name__)
# CORS
# https://flask-cors.corydolphin.com/en/latest/api.html#extension
CORS(app)
# JWT
app.config["JWT_SECRET_KEY"] = os.getenv("JWT_SECRET_KEY", default=secrets.token_hex())
app.config["JWT_ACCESS_TOKEN_EXPIRES"] = timedelta(hours=int(os.getenv("JWT_ACCESS_TOKEN_EXPIRES", 72)))
app.config["JWT_REFRESH_TOKEN_EXPIRES"] = timedelta(days=int(os.getenv("JWT_REFRESH_TOKEN_EXPIRES", 30)))
jwt = JWTManager(app)
# MongoDB
app.config["MONGO_URI"] = os.getenv("MONGO_URI")
mongo.init_app(app)
# Routes
app.register_blueprint(authentication_router, url_prefix='/auth')
app.register_blueprint(files_router, url_prefix='/files')
app.register_blueprint(instances_router, url_prefix='/instances')
app.register_blueprint(users_router, url_prefix='/users')
app.register_blueprint(ontology_router, url_prefix='/ontology')
app.register_blueprint(mapping_router, url_prefix='/mapping')
return app