chatbox2 / app.py
jacobinathanialpeterson's picture
Update app.py
c250f7a
raw
history blame
681 Bytes
import flask
import flask_cors
import os
messageArray = {}
# sets up the app
app = flask.Flask(__name__)
flask_cors.CORS(app)
# creates a API endpoint for the password input
@app.route('/postMessage', methods=['POST'])
def post():
nameIn = flask.request.get_json()['nameInput']
messageIn = flask.request.get_json()['messageInput']
n = len(messageArray)+1
messageArray.update({"message"+str(n): {"name": nameIn, "message": messageIn}})
return flask.jsonify("Message Sent")
@app.route('/messages', methods=['GET'])
def messages():
return flask.jsonify(messageArray)
if __name__ == "__main__":
app.run(debug=True,host="0.0.0.0",port=5000)