-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.py
50 lines (35 loc) · 1.27 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
from flask import Flask
from flask.helpers import send_from_directory
import os
from dotenv import load_dotenv
app = Flask(__name__, static_url_path='', static_folder='.')
app.config['CORS_HEADERS'] = 'Content-Type'
# Load environment variables
load_dotenv()
@app.after_request
def after_request_func(response):
# CORS section
response.headers.add("Access-Control-Allow-Origin", "*")
response.headers.add('Access-Control-Allow-Headers', "*")
response.headers.add('Access-Control-Allow-Methods', "*")
return response
# end CORS section
import error_handles
# Add your API endpoints here
from routes import users
# from routes import cars
# ...
@app.route('/')
def home_page():
try:
res = "<h1 style='position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);text-align:center'>FLASK API HOME<p>If you are seeing this page, Good Job. Your Flask app is ready! Add your endpoints in the /routes directory.</p></h1>"
return res
except Exception as e:
print(e)
# Setting Favicon
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'),
'favicon.ico', mimetype='image/vnd.microsoft.icon')
if __name__ == "__main__":
app.run(debug=True)