Skip to content
Merged
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_BACKEND_URL=https://contextual-chatbot-react.onrender.com/
53 changes: 53 additions & 0 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Deployment Configuration Guide

## Mobile Compatibility Fix

The main issue causing "Internal Server Error" on mobile devices was that the frontend was hardcoded to connect to `localhost:3001`, which mobile devices cannot access.

## Required Changes

### 1. Environment Variables

In your Vercel deployment, you need to set the following environment variable:

```
VITE_BACKEND_URL=https://your-backend-domain.com/api
```

Replace `your-backend-domain.com` with your actual backend domain (e.g., your Render.com domain).

### 2. CORS Configuration

Update the CORS allowed origins in your backend to include your Vercel domain:

```javascript
const allowedOrigins = [
'https://contextual-chatbot-react.vercel.app',
'http://localhost:5173',
'http://localhost:3000',
'http://localhost:3001',
'https://contextual-chatbot-react.onrender.com',
'https://your-actual-vercel-domain.vercel.app' // Add your actual Vercel domain
];
```

### 3. Vercel Environment Variables Setup

1. Go to your Vercel dashboard
2. Select your project
3. Go to Settings > Environment Variables
4. Add: `VITE_BACKEND_URL` = `https://your-backend-domain.com/api`
5. Redeploy your application

## Testing

After making these changes:
1. Deploy the updated code
2. Test on mobile devices
3. Check browser console for any remaining CORS or connection errors

## Common Issues

- **CORS errors**: Make sure your backend domain is in the allowed origins list
- **Socket connection errors**: Ensure the WebSocket URL is correctly formatted (without /api)
- **Environment variables not loading**: Make sure to redeploy after adding environment variables
10 changes: 9 additions & 1 deletion backend/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ app.use(cors({
'http://localhost:5173',
'http://localhost:3000',
'http://localhost:3001',
'https://contextual-chatbot-react.onrender.com'
'https://contextual-chatbot-react.onrender.com',
// Add your Vercel domain for mobile access
'https://contextual-chatbot-react.vercel.app/',
'https://contextual-chatbot-react.vercel.app/login',
'https://contextual-chatbot-react.vercel.app/register',

'https://contextual-chatbot-react.vercel.app/chat',
'https://vercel.com/chetramyts-projects/contextual-chatbot-react',

];

if (allowedOrigins.includes(origin)) {
Expand Down
4 changes: 3 additions & 1 deletion backend/src/sockets/socket.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const initSocketServer = (httpServer) => {
'http://localhost:5173',
'http://localhost:3000',
'http://localhost:3001',
'https://contextual-chatbot-react.onrender.com'
'https://contextual-chatbot-react.onrender.com',
// Add your Vercel domain for mobile access
'https://your-app-name.vercel.app'
];

if (allowedOrigins.includes(origin)) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/axios.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { logout } from '../redux/reducers/authSlice';
// import axios from "axios";

export const axiosInstance = axios.create({
baseURL: "http://localhost:3001/api",
baseURL: import.meta.env.VITE_BACKEND_URL || "http://localhost:3001/api",
// baseURL: "https://contextual-chatbot-react.onrender.com/api",
withCredentials: true,
});
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/ChatInterface.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ const ChatInterface = () => {
useEffect(() => {
if (isAuthenticated) {
dispatch(getChats()); // This fetches chats and then all messages
const newSocket = io("http://localhost:3001", { withCredentials: true });
const backendUrl = import.meta.env.VITE_BACKEND_URL || "http://localhost:3001";
const socketUrl = backendUrl.replace('/api', ''); // Remove /api for socket connection
const newSocket = io(socketUrl, { withCredentials: true });
setSocket(newSocket);
return () => newSocket.disconnect();
}
Expand Down