-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
32 lines (29 loc) · 1.15 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
# pip install Flask, Flask-RESTful, Flask-JWT, Flask-SQLALchemy
import os
from flask import Flask
from flask_restful import Api
from flask_jwt import JWT
from security import authenticate, identity
from resources.user import UserRegister
from resources.items import Item, ItemList
from resources.store import Store,StoreList
# @app.route("/")
# def hello():
# return "Hello World!"
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get("DATABASE_URL","sqlite:///data.db")
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False #turn off flask's SQLALCHEMY modification tracker?
app.secret_key = "abcd"
api = Api(app)
jwt = JWT(app,authenticate, identity) #/auth POST
#Header=> Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9
#creating routes
api.add_resource(Store, '/store/<string:name>')
api.add_resource(Item, '/item/<string:name>') # http://127.0.0.1:5001/student/rolf
api.add_resource(StoreList, '/stores')
api.add_resource(ItemList, '/items')
api.add_resource(UserRegister, '/register')
if __name__ == "__main__":
from db import db#importing here to avoid circular imports?
db.init_app(app)
app.run(port=5001, debug=True)