-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
60 lines (47 loc) · 1.6 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
''' This application was developed as a general purpose
API to be used by White RaBot for testing and business purposes '''
__title__ = 'Cloud RaBot Api'
__author__ = 'Jacob Weeks'
__license__ = 'MIT'
__copyright__ = 'Copyright 2017, Jacob Weeks'
## Import all of our required libraries
from flask import Flask, render_template, redirect, url_for, request
from flask_restful import Api
from flask_jwt import JWT
from db import db
from security import authenticate, identity
from resources.user import UserRegister
from resources.message import Message, MessageList
from resources.team import Team, TeamList
### Initilize App
application = Flask(__name__)
# Configure DB
application.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.db'
application.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# Security Key
application.secret_key = 'ImMrMeeseeksLookAtMee'
# Connect to restful
api = Api(application)
# Connect to DB
db.init_app(application)
### Creates the table on first request if does not exist
@application.before_first_request
def create_tables():
db.create_all()
#Create auth endpoint
jwt = JWT(application, authenticate, identity) # /auth
# Team End Points
api.add_resource(Team, '/team/<string:name>')
api.add_resource(TeamList, '/teams')
## Messages Endpoint
api.add_resource(Message, '/message/<string:team_id>')
api.add_resource(MessageList, '/messages')
## Registration Endpoint
api.add_resource(UserRegister, '/register')
#Index Route
@application.route("/")
def index():
return render_template('index.html')
if __name__ == '__main__':
#Run when app called
application.run(debug=True)