Skip to content

Commit 2549a32

Browse files
committed
fix the api and backend cors error
Signed-off-by: Naymul Islam <naymul504@gmail.com>
1 parent 6a1d7bc commit 2549a32

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

backend/main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@
77
from backend.proxy_manager import SmartProxyManager # Updated import
88
from backend.agent import run_agent
99
from fastapi.staticfiles import StaticFiles
10+
from fastapi.middleware.cors import CORSMiddleware
1011

1112
app = FastAPI()
1213

14+
15+
app.add_middleware(
16+
CORSMiddleware,
17+
allow_origins=["*"], # TODO add specific origins in production
18+
allow_credentials=True,
19+
allow_methods=["*"],
20+
allow_headers=["*"],
21+
)
22+
1323
tasks = {} # job_id → async.Task
1424
ws_subscribers = {} # job_id → { websocket, … }
1525
streaming_sessions = {} # job_id → browser_controller

frontend/src/components/JobForm.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState, useEffect } from 'react';
22
import { Play, Download, Monitor, Eye, EyeOff, Sparkles, ArrowRight } from 'lucide-react';
33
import { WebSocketManager } from '../services/WebSocketManager';
4+
const API_BASE_URL = 'http://localhost:8000';
45

56
interface JobFormProps {
67
wsManager: WebSocketManager;
@@ -49,7 +50,7 @@ export const JobForm: React.FC<JobFormProps> = ({ wsManager, onJobCreated }) =>
4950
const finalFormat = detectedFormat || format;
5051

5152
try {
52-
const response = await fetch('/job', {
53+
const response = await fetch(`${API_BASE_URL}/job`, {
5354
method: 'POST',
5455
headers: { 'Content-Type': 'application/json' },
5556
body: JSON.stringify({
@@ -78,7 +79,7 @@ export const JobForm: React.FC<JobFormProps> = ({ wsManager, onJobCreated }) =>
7879
if (!currentJobId) return;
7980

8081
try {
81-
const response = await fetch(`/download/${currentJobId}`);
82+
const response = await fetch(`${API_BASE_URL}/download/${currentJobId}`);
8283
if (response.ok) {
8384
const blob = await response.blob();
8485
const url = window.URL.createObjectURL(blob);

0 commit comments

Comments
 (0)