-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
92 lines (77 loc) · 2.58 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#----------------------------------------------------------------------------#
# Imports
#----------------------------------------------------------------------------#
from flask import Flask, render_template, request
from flask_sqlalchemy import SQLAlchemy
import logging
from flask import Flask, send_from_directory
from logging import Formatter, FileHandler
from controllers import *
from flask_jwt_extended import JWTManager
from models import Users, Items, Rentals, Permissions, Comments, Locations, db_session
import os
#----------------------------------------------------------------------------#
# App Config.
#----------------------------------------------------------------------------#
app = Flask(__name__, static_folder='wrent_frontend/build')
app.config.from_object('config')
app.register_blueprint(controllers)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
jwt = JWTManager(app)
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def index(path):
if path != "" and os.path.exists(app.static_folder + '/' + path):
return send_from_directory(app.static_folder, path)
else:
return send_from_directory(app.static_folder, 'index.html')
# Automatically tear down SQLAlchemy.
@app.teardown_request
def shutdown_session(exception=None):
db_session.remove()
# Login required decorator.
'''
def login_required(test):
@wraps(test)
def wrap(*args, **kwargs):
if 'logged_in' in session:
return test(*args, **kwargs)
else:
flash('You need to login first.')
return redirect(url_for('login'))
return wrap
'''
# # Error handlers.
#
#
# @app.errorhandler(500)
# def internal_error(error):
# #db_session.rollback()
# return render_template('errors/500.html'), 500
#
#
# @app.errorhandler(404)
# def not_found_error(error):
# return render_template('errors/404.html'), 404
if not app.debug:
file_handler = FileHandler('error.log')
file_handler.setFormatter(
Formatter('%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]')
)
app.logger.setLevel(logging.INFO)
file_handler.setLevel(logging.INFO)
app.logger.addHandler(file_handler)
app.logger.info('errors')
#----------------------------------------------------------------------------#
# Launch.
#----------------------------------------------------------------------------#
# Default port:
if __name__ == '__main__':
app.run()
# Or specify port manually:
'''
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)
'''