Skip to content

Commit f7aba06

Browse files
committed
Fix Python server startup and Flask configuration
- Implement robust Python detection that tries python3 first, then python - Update Flask app template to bind to 0.0.0.0 and use PORT environment variable - Fix Flask server startup command to use direct Python execution instead of flask CLI - Ensure proper network binding for all Python web frameworks
1 parent 238f876 commit f7aba06

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/ipc/handlers/createFromTemplate.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,7 @@ async function setupFlask(backendPath: string) {
14841484

14851485
// Create app.py
14861486
const appContent = `from flask import Flask
1487+
import os
14871488
14881489
app = Flask(__name__)
14891490
@@ -1496,7 +1497,8 @@ def get_items():
14961497
return {'items': [{'id': 1, 'name': 'Sample Item'}]}
14971498
14981499
if __name__ == '__main__':
1499-
app.run(debug=True)
1500+
port = int(os.environ.get('PORT', 5000))
1501+
app.run(debug=True, host='0.0.0.0', port=port)
15001502
`;
15011503
await fs.writeFile(appPath, appContent);
15021504

@@ -1899,7 +1901,7 @@ export async function getStartCommandForFramework(framework: string): Promise<st
18991901
return `uvicorn main:app --reload --host 0.0.0.0 --port ${fastapiPort}`;
19001902
case "flask":
19011903
const flaskPort = await findAvailablePort(5000);
1902-
return `python -c 'import os; os.environ.setdefault("FLASK_APP", "app.py"); os.system("flask run --host=0.0.0.0 --port=${flaskPort}")'`;
1904+
return `PORT=${flaskPort} bash -c 'if command -v python3 >/dev/null 2>&1; then python3 app.py; elif command -v python >/dev/null 2>&1; then python app.py; else echo "Python not found. Please install Python 3."; exit 1; fi'`;
19031905
default:
19041906
logger.warn(`Unknown framework for server start: ${framework}`);
19051907
return "";

0 commit comments

Comments
 (0)