-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
31 lines (24 loc) · 1.08 KB
/
Copy pathapp.py
File metadata and controls
31 lines (24 loc) · 1.08 KB
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
from flask import Flask
from api.routes import api
from api.models import db
import os
app = Flask(__name__)
# Configure SQLite database using environment variable or default path
database_path = os.environ.get('SQLALCHEMY_DATABASE_URI', 'sqlite:///tasks.db')
app.config['SQLALCHEMY_DATABASE_URI'] = database_path
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# Initialize the database with the app
db.init_app(app)
# Register the blueprint with a URL prefix
app.register_blueprint(api, url_prefix='') # Empty prefix to serve from root
# Create database tables
with app.app_context():
db.create_all()
if __name__ == '__main__':
# Use environment variable for host to allow connections from outside the container
host = os.environ.get('HOST', '0.0.0.0')
port = int(os.environ.get('PORT', 5001))
# Debug mode is opt-in via the DEBUG environment variable. It defaults to
# off because the Werkzeug debugger allows arbitrary code execution.
debug = os.environ.get('DEBUG', '').strip().lower() in ('1', 'true', 'yes', 'on')
app.run(host=host, port=port, debug=debug)