-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
61 lines (44 loc) · 1.72 KB
/
Copy pathapp.py
File metadata and controls
61 lines (44 loc) · 1.72 KB
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
import os
from flask import Flask
from application.config import LocalDevelopmentConfig
from application.database import db
import logging
from flask_restful import Resource, Api
from flask_login import LoginManager
logging.basicConfig(filename='debug.log', level=logging.DEBUG,
format=f'%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s')
def create_app():
app = Flask(__name__, template_folder="templates")
if os.getenv('ENV', "development") == "production":
app.logger.info("Currently no production config is setup.")
raise Exception("Currently no production config is setup.")
else:
app.logger.info("Staring Local Development.")
print("Staring Local Development")
app.config.from_object(LocalDevelopmentConfig)
if not os.path.exists('db_directory'):
os.mkdir('db_directory')
db.init_app(app)
api = Api(app)
app.app_context().push()
app.logger.info("App setup complete")
return app, api
# app.logger.info("App setup complete")
app, api = create_app()
app.static_folder = 'static'
login_manager = LoginManager()
login_manager.init_app(app)
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))
# Import all the controllers so they are loaded
from application.articles.controllers import *
from application.controllers import *
from application.auth.controllers import *
# Crete all the API endpoints
from application.api import UserAPI, ArticleAPI
api.add_resource(UserAPI, "/api/user", "/api/user/<string:username>")
api.add_resource(ArticleAPI, "/api/article", "/api/article/<int:article_id>")
if __name__ == '__main__':
# Run the Flask app
app.run(host='127.0.0.1', port=5000)