app.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Sun Jul 14 11:50:51 2019
  5. @author: dagarcos
  6. """
  7. import os
  8. from flask import Flask, flash, render_template, redirect, request, url_for
  9. from flask_cors import CORS, cross_origin
  10. from models.db import db
  11. from controllers.mainController import mainController
  12. app = Flask(__name__)
  13. app.secret_key = os.urandom(12)
  14. app.config['SQLALCHEMY_DATABASE_URI'] = ""
  15. app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
  16. db.init_app(app)
  17. app.register_blueprint(mainController)
  18. CORS(app, origins = "*", allow_headers=["Content-Type", "content-type", "Authorization", "Access-Control-Allow-Credentials", "Access-Control-Allow-Headers", "Access-Control-Allow-Origin"], supports_credentials=True)
  19. if __name__ == '__main__':
  20. app.run(host='0.0.0.0', debug=True)
  21. @app.after_request
  22. def after_request(response):
  23. response.headers.add('Access-Control-Allow-Origin', '*')
  24. response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
  25. response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
  26. return response