api.py 981 Bytes
Newer Older
1
from flask import Flask
James Kirk's avatar
James Kirk committed
2
from flask_cors import CORS
3
from flask_restful import Api
James Kirk's avatar
James Kirk committed
4

5
from endpoints.clients import Client, ClientList
James Kirk's avatar
James Kirk committed
6
from endpoints.notify import Notify
7
from endpoints.receive import Receive
8
from endpoints.send import Send
9
from endpoints.token import Token
10 11
from models.token_model import TokenModel

12

13 14
import os

15 16
token = TokenModel()
token.setSecret()
17 18


19 20 21 22 23 24 25 26 27 28 29 30 31
def create_app():
    app = Flask(__name__)
    api = Api(app)
    CORS(app, resources={r"*": {"origins": "http://localhost:8086"}})

    api.add_resource(ClientList, "/client")
    api.add_resource(Client, "/client/<client_id>")
    api.add_resource(Receive, "/receive")
    api.add_resource(Send, "/send")
    api.add_resource(Notify, "/notify")
    api.add_resource(Token, "/token")
    return app

32

33 34
flask_host = os.getenv("FLASK_HOST", "localhost") # Sets to whatever MQ_HOST is, or defaults to localhost

35
if __name__ == "__main__":
36
    app = create_app()
37
    app.run(debug=False, port=8087, host=flask_host)