27 lines
637 B
Python
27 lines
637 B
Python
#!/usr/bin/env python3
|
|
"""Contacts API"""
|
|
import os
|
|
|
|
from . import db
|
|
from .contacts import Contacts, Contact
|
|
|
|
from flask import Flask, request, jsonify
|
|
from flask_restful import Api
|
|
from flask_cors import CORS
|
|
|
|
def create_app(test_config=None):
|
|
"""Initiate Flask app and bind routes"""
|
|
app = Flask(__name__)
|
|
db.init_app(app)
|
|
api = Api(app)
|
|
CORS(app, resources={r"/api/*": {"origins": "*"}})
|
|
api.add_resource(Contacts, '/api/contacts')
|
|
api.add_resource(Contact, '/api/contacts/<int:uid>')
|
|
|
|
return app
|
|
|
|
|
|
if __name__ == "__main__":
|
|
created_app = create_app()
|
|
created_app.run(port=5000, debug=False)
|