Skip to content

Commit 2caefda

Browse files
committed
Production Deployment (Phase 2 - Under Development)
1 parent f9ca22c commit 2caefda

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

backend/app/__init__.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,20 @@ def create_app() -> Flask:
2525
# Initialize Flask app
2626
app = Flask(__name__)
2727

28-
# Configure CORS based on environment
28+
# Configure CORS - allow all origins in development and specific origins in production
2929
is_production = os.getenv("FLASK_ENV") == "production"
30+
3031
if is_production:
3132
# In production, allow specific origins
3233
allowed_origins = [
3334
"https://hxndev.github.io", # GitHub Pages domain
34-
"http://localhost:5173" # Local dev frontend
35+
"http://localhost:5173" # Local dev frontend (for testing)
3536
]
36-
CORS(app, origins=allowed_origins, supports_credentials=True)
37+
CORS(app, resources={r"/api/*": {"origins": allowed_origins}}, supports_credentials=True)
3738
else:
38-
# In development, allow all origins
39-
CORS(app)
39+
# In development, allow all origins with proper preflight handling
40+
CORS(app, resources={r"/api/*": {"origins": "*"}}, supports_credentials=True)
4041

41-
# API key management is now handled per-request in routes
42-
# Default Gemini configuration is still set up here without a key
43-
# The actual key will be passed with each request
44-
4542
# Import and register blueprints
4643
# Using import_module to avoid circular imports
4744
routes = import_module(".routes", package="app")

backend/app/routes.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ def check_file_size(file) -> bool:
114114
@api_bp.before_request
115115
def before_request():
116116
"""Middleware to check API key for all requests except health check"""
117-
# Skip API key validation for health check endpoint
118-
if request.path == "/api/health":
117+
# Skip API key validation for health check endpoint and OPTIONS requests
118+
if request.path == "/api/health" or request.method == 'OPTIONS':
119119
return
120120

121121
# Get and validate API key
@@ -149,16 +149,19 @@ def analyze():
149149
logger.error("No resume file received")
150150
return jsonify({"success": False, "error": "No resume file provided"}), 400
151151

152-
job_details_str = request.form.get("job_links", "[]") # Default to an empty list if missing
153-
154152
resume = request.files["resume"]
155153
# Check file size
156154
if not check_file_size(resume):
157155
return jsonify({"success": False, "error": f"Resume file too large. Maximum size is {MAX_FILE_SIZE // (1024 * 1024)}MB"}), 400
158156

159-
job_details_str = request.form["job_links"]
157+
# Get job details from the request
158+
job_details_str = request.form.get("job_details", "[]")
159+
if not job_details_str:
160+
# For backwards compatibility, check job_links as well
161+
job_details_str = request.form.get("job_links", "[]")
162+
160163
logger.info(f"Received resume: {resume.filename}")
161-
logger.info(f"Received job links: {job_details_str[:200]}") # Print only first 200 chars
164+
logger.info(f"Received job details: {job_details_str[:200]}") # Print only first 200 chars
162165

163166
# Parse job details with better error handling
164167
try:

frontend/src/pages/Home.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ const Home = () => {
104104
formData.append('resume', textFile, 'resume.txt');
105105
}
106106

107-
// Convert job details to a JSON string (Even if empty)
108-
formData.append('job_links', JSON.stringify(jobDetails || []));
109-
110107
try {
111108
// Convert job details to a JSON string
112109
const jobDetailsJson = JSON.stringify(jobDetails);
113110
formData.append('job_details', jobDetailsJson);
111+
112+
// For backward compatibility, also add as job_links
113+
formData.append('job_links', jobDetailsJson);
114114
} catch (error) {
115115
console.error('Error stringifying job details:', error);
116116
notifications.show({
@@ -323,4 +323,4 @@ const Home = () => {
323323
);
324324
};
325325

326-
export default Home;
326+
export default Home;

frontend/src/utils/apiConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,4 @@ export const addApiKeyToRequestConfig = (config = {}) => {
113113
export const getApiUrl = (endpoint) => {
114114
const cleanEndpoint = endpoint.startsWith('/') ? endpoint.slice(1) : endpoint;
115115
return `${API_BASE_URL}/${cleanEndpoint}`;
116-
};
116+
};

frontend/vite.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import react from '@vitejs/plugin-react';
33

44
export default defineConfig({
55
plugins: [react()],
6-
base: '/JobFit/', // Base path for GitHub Pages deployment
6+
base: process.env.NODE_ENV === 'production' ? '/JobFit/' : '/', // Base path for GitHub Pages in production
77
server: {
88
port: 5173,
99
proxy: {
1010
'/api': {
11-
target: 'http://localhost:5000',
11+
target: 'http://localhost:5050',
1212
changeOrigin: true,
1313
secure: false,
1414
},

0 commit comments

Comments
 (0)