Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
264 changes: 230 additions & 34 deletions .cursor/rules/project-rules.md

Large diffs are not rendered by default.

30 changes: 26 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
# Flask Configuration
FLASK_APP=backend/app.py
FLASK_ENV=development
GEMINI_API_KEY=your_gemini_api_key
SECRET_KEY=your_secret_key_here
FLASK_RUN_PORT=5000
SECRET_KEY=your-secret-key-here
WTF_CSRF_SECRET_KEY=your-csrf-secret-key

FLASK_RUN_PORT = 5000
#set it the same as the env file in react-frontend
# Database Configuration
DATABASE_URL=postgresql://postgres:password@localhost:5432/instantapply_dev

# Optional: Separate test database (only needed if running automated tests)
# TEST_DATABASE_URL=postgresql://postgres:password@localhost:5432/instantapply_test

# Database Connection Pool Settings (optional)
DB_POOL_SIZE=5
DB_MAX_OVERFLOW=10
DB_POOL_TIMEOUT=30
DB_POOL_RECYCLE=1800

# Frontend URL
FRONTEND_URL=http://127.0.0.1:8080

# Email Configuration
MAIL_SERVER=smtp.gmail.com
MAIL_PORT=587
MAIL_USE_TLS=True
MAIL_USERNAME=your-email@gmail.com
MAIL_PASSWORD=your-app-password
MAIL_DEFAULT_SENDER=your-email@gmail.com
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ RUN playwright install-deps chromium
COPY app.py .
COPY backend/ backend/

# Create uploads directory if it doesn't exist
RUN mkdir -p backend/uploads
# Create uploads directory if it doesn't exist with proper permissions
RUN mkdir -p backend/uploads && \
chmod 777 backend/uploads && \
mkdir -p uploads && \
chmod 777 uploads

# Create instance directory for SQLite database and ensure it's writable
RUN mkdir -p instance && \
Expand Down Expand Up @@ -89,7 +92,7 @@ ENV PYTHONPATH=/app
ENV FLASK_APP=app.py

# Set a default SQLite database URL that explicitly uses the instance directory
ENV DATABASE_URL="sqlite:////app/instance/instant_apply.db"
ENV DATABASE_URL="postgresql://postgres:password@localhost:5432/instantapply_dev"

# Expose the port the app runs on
EXPOSE 8000
Expand Down
91 changes: 50 additions & 41 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,64 @@
#!/usr/bin/env python3
"""
Root-level app.py to help Azure Web App find and run the Flask application
Properly handles path setup for both development and production environments
InstantApply - Main application entry point
Run this from the project root directory
"""

import os
import sys
from pathlib import Path

def setup_paths():
"""Setup proper paths for the application"""
# Get the absolute path to the root directory
ROOT_DIR = os.path.abspath(os.path.dirname(__file__))

# Ensure we're working from the correct root directory
os.chdir(ROOT_DIR)

# Add paths to Python path
sys.path.insert(0, ROOT_DIR)
sys.path.insert(0, os.path.join(ROOT_DIR, 'backend'))

return ROOT_DIR
# Get the current directory (project root)
project_root = Path(__file__).parent.absolute()
backend_dir = project_root / "backend"

# Add both directories to Python path
sys.path.insert(0, str(project_root))
sys.path.insert(0, str(backend_dir))

# Set working directory to backend for relative imports
os.chdir(backend_dir)

def create_flask_app():
"""Create and configure the Flask application"""
ROOT_DIR = setup_paths()
"""Create the Flask application with proper path setup"""
try:
# Now import from backend.app
from backend.app import create_app
return create_app()
except ImportError as e:
print(f"❌ Import error: {e}")
print(f"Current working directory: {os.getcwd()}")
print(f"Python path: {sys.path[:3]}")
raise

def main():
"""Main entry point"""
print(f"🚀 Starting InstantApply from: {project_root}")
print(f"📁 Backend directory: {backend_dir}")
print(f"💼 Working directory: {os.getcwd()}")

# Ensure we have required environment variables
from dotenv import load_dotenv
load_dotenv()

# Set environment variable to ensure proper database path
if not os.environ.get('DATABASE_URL'):
os.environ['DATABASE_URL'] = f'sqlite:///{ROOT_DIR}/backend/instant_apply.db'
print("⚠️ No DATABASE_URL found in environment, using default PostgreSQL")
os.environ['DATABASE_URL'] = 'postgresql://postgres:password@localhost:5432/instantapply_dev'

# Change to backend directory for relative imports to work
backend_dir = os.path.join(ROOT_DIR, 'backend')
os.chdir(backend_dir)
print(f"🗄️ Database URL: {os.environ.get('DATABASE_URL')}")

# Import and create the app
from backend.app import create_app
return create_app()
# Create and run the app
try:
app = create_flask_app()
port = int(os.environ.get('FLASK_RUN_PORT', 8080))
print(f"✅ Flask app created successfully!")
print(f"🌐 Starting server on http://0.0.0.0:{port}")
app.run(debug=True, host='0.0.0.0', port=port)
except Exception as e:
print(f"❌ Failed to start application: {e}")
import traceback
traceback.print_exc()
sys.exit(1)

# Create the app instance for WSGI servers (like Azure, Gunicorn, etc.)
app = create_flask_app()

if __name__ == "__main__":
"""Direct execution - for development"""
print(f"Working directory: {os.getcwd()}")
print(f"Python path (first 3): {sys.path[:3]}")
print("✅ Flask app created successfully!")
print("🚀 Starting Flask server...")

# Run the Flask app
app.run(
host="0.0.0.0",
port=int(os.environ.get('FLASK_RUN_PORT', 5000)),
debug=os.environ.get('FLASK_ENV') == 'development'
)
if __name__ == '__main__':
main()
9 changes: 9 additions & 0 deletions azure-deploy/web.config
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@
<environmentVariables>
<environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
<environmentVariable name="PYTHONPATH" value="%home%\site\wwwroot" />
<environmentVariable name="UPLOAD_FOLDER" value="%home%\site\wwwroot\uploads" />
<environmentVariable name="MAX_CONTENT_LENGTH" value="33554432" />
</environmentVariables>
</httpPlatform>

<!-- Configure request limits for file uploads -->
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="33554432" /> <!-- 32MB -->
</requestFiltering>
</security>
<httpErrors errorMode="Detailed"></httpErrors>
<asp scriptErrorSentToBrowser="true"/>
<!-- Enable detailed logs for troubleshooting -->
Expand Down
4 changes: 2 additions & 2 deletions backend/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
}

headers = {
"x-rapidapi-key": "6fcedf620cmsh832cb5be381cb42p1d03dbjsnc9e6c6d456f8",
"x-rapidapi-host": "jsearch.p.rapidapi.com"
"x-rapidapi-key": "6fcedf620cmsh832cb5be381cb42p1d03dbjsnc9e6c6d456f8",
"x-rapidapi-host": "jsearch.p.rapidapi.com"
}

response = requests.get(url, headers=headers, params=querystring)
Expand Down
143 changes: 0 additions & 143 deletions backend/GEMINI_MULTI_KEY_SETUP.md

This file was deleted.

Loading
Loading