/
server.py
41 lines (30 loc) · 1.01 KB
/
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
38
39
40
41
from flask import Flask, jsonify, request, session, send_from_directory, abort
import pymongo
app = Flask(__name__)
app.debug = True
app.secret_key = 'WOW_SO_SECRET_ZOMG'
db = pymongo.MongoClient().user_data
@app.route('/')
def root():
return send_from_directory(app.root_path + '/static/', 'index.html')
@app.route('/<path:filename>')
def static_file(filename):
return send_from_directory(app.root_path + '/static/', filename)
@app.route('/status')
def status():
return jsonify({'message': 'OK'})
@app.route('/add-user', methods=['POST'])
def add_user():
try:
# Check for correct content type
if not request.json:
abort(400)
user = {'phone_number': request.json['phoneNumber'],
'region': request.json['region'],
'address': request.json['address']}
db.users.insert(user)
return jsonify({'message': 'All good!'})
except:
abort(400)
if __name__ == '__main__':
app.run(host='www.tweetpd.com', port=80, debug=True) # Yeah, I know the debug server shouldn't be used in prod. This is a hackathon.