-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
37 lines (30 loc) · 809 Bytes
/
server.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
from flask import Flask, request
app = Flask(__name__)
messages = []
@app.route("/")
def home():
return "no args"
@app.route("/send", methods=["POST"])
def send():
try:
data = request.get_json()
name = data['name']
message = data['message']
messages.append("[" + str(name) + "]: " + str(message))
return "success"
except:
return "internal error"
@app.route("/update", methods=["GET"])
def update():
return str(messages)
@app.route("/get_last_message", methods=["GET"])
def get_last_message():
if len(messages) > 0:
return str(messages[len(messages) - 1])
else:
return "Null"
@app.route("/get_last_index", methods=["GET"])
def get_last_index():
return str(len(messages))
if __name__ == "__main__":
app.run()