-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
38 lines (29 loc) · 906 Bytes
/
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
import os
import util
import db
from flask import Flask, json
from flask_cors import CORS
from flask_restful import Api
from resources.user import User
app = Flask(__name__)
# Allow cross domain apps to access API
CORS(app)
# Provide Mongo Atlas URI, stored in config file
app.config["MONGO_URI"] = os.getenv("MONGO_URI_MASTER")
# Set custom JSON Encoder for Mongo Object
app.json_encoder = util.MongoEncoder
db.mongo.init_app(app)
api = Api(app)
api.add_resource(User, "/user")
# Vanilla Flask route
@app.route("/", methods=["GET"])
def index():
return "Welcome to my ZotHacks 2020 project!"
# Handles validation errors and returns JSON Object
@app.errorhandler(422)
@app.errorhandler(400)
def handle_error(err):
messages = err.data.get("messages", ["Invalid request."])
return json.jsonify({"errors": messages}), err.code
if __name__ == "__main__":
app.run(port=5000,debug=True)