Skip to content

Commit 713798a

Browse files
committed
Simplify to pure Flask deployment without external WSGI servers
1 parent 61bd697 commit 713798a

3 files changed

Lines changed: 9 additions & 23 deletions

File tree

infra/main.bicep

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ resource appService 'Microsoft.Web/sites@2024-04-01' = {
6262
httpsOnly: true
6363
siteConfig: {
6464
linuxFxVersion: 'PYTHON|3.12'
65-
appCommandLine: 'python -m uvicorn main:app --host 0.0.0.0 --port 8000'
6665
appSettings: [
66+
{
67+
name: 'WEBSITES_PORT'
68+
value: '8000'
69+
}
6770
{
6871
name: 'SECRET_KEY'
6972
value: secretKey

main.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,13 @@
1212
from src.models import db # noqa: E402
1313

1414
# Create Flask app
15-
flask_app = create_app()
15+
app = create_app()
1616

1717
# Initialize database tables
18-
with flask_app.app_context():
18+
with app.app_context():
1919
db.create_all()
2020

21-
# Create ASGI app for Uvicorn
22-
from werkzeug.middleware.proxy_fix import ProxyFix # noqa: E402
23-
flask_app.wsgi_app = ProxyFix(
24-
flask_app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1
25-
)
26-
27-
# For Uvicorn
28-
try:
29-
from asgiref.wsgi import WsgiToAsgi # noqa: E402
30-
app = WsgiToAsgi(flask_app)
31-
except ImportError:
32-
# Fallback: use Flask directly
33-
app = flask_app
34-
3521
if __name__ == '__main__':
36-
flask_app.run(debug=False, host='0.0.0.0', port=8000)
22+
# Get port from environment variable (Azure sets this as WEBSITES_PORT)
23+
port = int(os.environ.get('WEBSITES_PORT', os.environ.get('PORT', 8000)))
24+
app.run(debug=False, host='0.0.0.0', port=port)

requirements.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,5 @@ Flask==3.0.0
22
Flask-CORS==4.0.0
33
Flask-SQLAlchemy==3.1.1
44
SQLAlchemy==2.0.23
5-
uvicorn==0.24.0
6-
asgiref==3.7.2
75
python-dotenv==1.0.0
8-
azure-identity==1.15.0
9-
azure-keyvault-secrets==4.8.0
10-
azure-monitor-opentelemetry==1.2.0
116
requests==2.31.0

0 commit comments

Comments
 (0)