-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
52 lines (44 loc) · 1.77 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
import config_vars as config
import models
from auth import auth
from resources.courses import courses_api
from resources.reviews import reviews_api
from resources.users import user_api
from resources.edits import edits_api
from resources.comments import comments_api
from resources.votes import votes_api
from resources.tags import tags_api
from flask import Flask, g, jsonify
# from flask_limiter import Limiter
# from flask_limiter.util import get_ipaddr
from flask_cors import CORS
app = Flask(__name__)
app.register_blueprint(courses_api) # add url prefix here
app.register_blueprint(reviews_api, url_prefix='/api/v1')
app.register_blueprint(user_api, url_prefix='/api/v1')
app.register_blueprint(edits_api, url_prefix='/api/v1')
app.register_blueprint(comments_api, url_prefix='/api/v1')
app.register_blueprint(votes_api, url_prefix='/api/v1')
app.register_blueprint(tags_api, url_prefix='/api/v1')
CORS(app)
# simple ip address limit. other options are the user token or uscourseser name.
# limiter = Limiter(app,
# global_limits=[config.DEFAULT_RATE],
# key_func=get_ipaddr)
# # specifiy a limit for a specific blueprint
# limiter.limit('40/day')(user_api)
# method_limiter = limiter.limit(config.DEFAULT_RATE, per_method=True,
# methods=['post', 'put', 'delete'])
# method_limiter(courses_api)
# method_limiter(reviews_api)
# # exempt a blueprint from limits
# limiter.exempt(courses_api)
# limiter.exempt(reviews_api)
@app.route('/api/v1/users/token', methods=['GET'])
@auth.login_required
def get_auth_token():
token = g.user.generate_auth_token()
return jsonify({'token': token.decode('ascii')})
if __name__ == '__main__':
models.initialize()
app.run(host=config.HOST, port=config.PORT, debug=config.DEBUG)