-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
55 lines (44 loc) · 1.82 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
# import from packages
from flask import Flask
from flask_restful import Api
from flask_migrate import Migrate
# imports from manually created files
from resources.user import CreateUserResource, UserResource, MeResource, UserPostListResource
from resources.post import PostListResource, PostResource
from resources.token import TokenResource, RefreshResource, RevokeAccessResource, blacklist
from database import db
from jwt_manage import jwt
from caching import cache
def create_app():
app = Flask(__name__)
DEBUG = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://varun_reviewbook:sharma@localhost/restaurants_data'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SECRET_KEY'] = 'topsecret'
app.config['JWT_ERROR_MESSAGE'] = 'message'
app.config['JWT_BLACKLIST_ENABLED'] = True
app.config['JWT_BLACKLIST_TOKEN_CHECKS'] = ['access', 'refresh']
app.config['CACHE_TYPE'] = 'simple'
app.config['CACHE_DEFAULT_TIMEOUT'] = 10 * 60
db.init_app(app)
jwt.init_app(app)
cache.init_app(app)
migrate = Migrate(app, db)
@jwt.token_in_blacklist_loader
def check_if_token_in_blacklist(decrypted_token):
jti = decrypted_token['jti']
return jti in blacklist
api = Api(app)
api.add_resource(PostListResource, '/posts')
api.add_resource(PostResource, '/posts/<int:id>')
api.add_resource(CreateUserResource, '/users')
api.add_resource(UserResource, '/users/<string:username>')
api.add_resource(MeResource, '/me')
api.add_resource(UserPostListResource, '/users/<string:username>/posts')
api.add_resource(TokenResource, '/token')
api.add_resource(RefreshResource, '/refresh')
api.add_resource(RevokeAccessResource, '/revoke')
return app
if __name__ == '__main__':
app = create_app()
app.run(debug=True)