Skip to content

Commit 92334b7

Browse files
Added render.yaml
1 parent 50a516a commit 92334b7

4 files changed

Lines changed: 202 additions & 3 deletions

File tree

DEPLOYMENT.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Deployment Guide for Render
2+
3+
This guide will help you deploy the SecureComm Chat application on Render.
4+
5+
## Prerequisites
6+
7+
- A GitHub account
8+
- A Render account (sign up at https://render.com)
9+
- Your code pushed to a GitHub repository
10+
11+
## Deployment Steps
12+
13+
### Option 1: Using render.yaml (Recommended)
14+
15+
1. **Push your code to GitHub**
16+
```bash
17+
git init
18+
git add .
19+
git commit -m "Initial commit"
20+
git remote add origin <your-github-repo-url>
21+
git push -u origin main
22+
```
23+
24+
2. **Connect to Render**
25+
- Go to https://dashboard.render.com
26+
- Click "New +"
27+
- Select "Blueprint"
28+
- Connect your GitHub repository
29+
- Render will automatically detect the `render.yaml` file
30+
31+
3. **Configure Environment Variables**
32+
33+
For the **backend service**:
34+
- `FRONTEND_URL`: Set this to your frontend URL after deployment (e.g., `https://securecomm-frontend.onrender.com`)
35+
36+
For the **frontend service**:
37+
- `VITE_SERVER_URL`: Set this to your backend URL (e.g., `https://securecomm-backend.onrender.com`)
38+
- `VITE_SUPABASE_ANON_KEY`: Your Supabase anonymous key
39+
40+
4. **Deploy**
41+
- Click "Apply" to deploy both services
42+
- Wait for the deployment to complete (this may take a few minutes)
43+
44+
5. **Update CORS Settings**
45+
- After frontend deploys, note the URL
46+
- Update the backend's `FRONTEND_URL` environment variable
47+
- The backend will automatically restart
48+
49+
### Option 2: Manual Deployment
50+
51+
#### Deploy Backend
52+
53+
1. Go to https://dashboard.render.com
54+
2. Click "New +" → "Web Service"
55+
3. Connect your GitHub repository
56+
4. Configure:
57+
- **Name**: securecomm-backend
58+
- **Environment**: Node
59+
- **Build Command**: `npm install`
60+
- **Start Command**: `npm run start`
61+
- **Plan**: Free
62+
5. Add environment variables:
63+
- `NODE_ENV`: production
64+
- `PORT`: 3001
65+
- `FRONTEND_URL`: (add after frontend deployment)
66+
6. Click "Create Web Service"
67+
68+
#### Deploy Frontend
69+
70+
1. Click "New +" → "Static Site"
71+
2. Connect your GitHub repository
72+
3. Configure:
73+
- **Name**: securecomm-frontend
74+
- **Build Command**: `npm install && npm run build`
75+
- **Publish Directory**: `dist`
76+
4. Add environment variables:
77+
- `VITE_SERVER_URL`: Your backend URL from step above
78+
- `VITE_SUPABASE_URL`: https://0ec90b57d6e95fcbda19832f.supabase.co
79+
- `VITE_SUPABASE_ANON_KEY`: Your Supabase key
80+
5. Click "Create Static Site"
81+
82+
#### Final Configuration
83+
84+
1. Copy your frontend URL
85+
2. Go to backend service settings
86+
3. Add `FRONTEND_URL` environment variable with the frontend URL
87+
4. Backend will automatically redeploy
88+
89+
## Important Notes
90+
91+
### Free Tier Limitations
92+
93+
- Free services spin down after 15 minutes of inactivity
94+
- First request after spin-down may take 30-60 seconds
95+
- WebSocket connections may be interrupted during spin-down
96+
- Consider upgrading to paid plan for production use
97+
98+
### Environment Variables
99+
100+
Make sure to set these environment variables correctly:
101+
102+
**Backend:**
103+
- `FRONTEND_URL`: Your deployed frontend URL
104+
- `PORT`: 3001 (or use Render's default)
105+
- `NODE_ENV`: production
106+
107+
**Frontend:**
108+
- `VITE_SERVER_URL`: Your deployed backend URL
109+
- `VITE_SUPABASE_URL`: Your Supabase project URL
110+
- `VITE_SUPABASE_ANON_KEY`: Your Supabase anonymous key
111+
112+
### Troubleshooting
113+
114+
**Connection Issues:**
115+
- Verify environment variables are set correctly
116+
- Check that CORS is properly configured
117+
- Ensure backend URL in frontend matches actual backend URL
118+
- Check browser console for detailed error messages
119+
120+
**WebSocket Issues:**
121+
- Render's free tier may have WebSocket limitations
122+
- Consider using polling as fallback (already configured)
123+
- Check that both services are awake and running
124+
125+
**Build Failures:**
126+
- Check build logs in Render dashboard
127+
- Verify all dependencies are in package.json
128+
- Ensure Node version compatibility
129+
130+
### Monitoring
131+
132+
- Check service logs in Render dashboard
133+
- Monitor health check endpoint: `<backend-url>/health`
134+
- Use browser console for frontend debugging
135+
136+
## Support
137+
138+
For issues specific to Render deployment, check:
139+
- Render documentation: https://render.com/docs
140+
- Render community: https://community.render.com

render.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
services:
2+
# Backend Web Service
3+
- type: web
4+
name: securecomm-backend
5+
env: node
6+
region: oregon
7+
plan: free
8+
buildCommand: npm install
9+
startCommand: npm run start
10+
healthCheckPath: /health
11+
envVars:
12+
- key: NODE_ENV
13+
value: production
14+
- key: PORT
15+
value: 3001
16+
- key: FRONTEND_URL
17+
sync: false
18+
19+
# Frontend Static Site
20+
- type: web
21+
name: securecomm-frontend
22+
env: static
23+
region: oregon
24+
plan: free
25+
buildCommand: npm install && npm run build
26+
staticPublishPath: ./dist
27+
routes:
28+
- type: rewrite
29+
source: /*
30+
destination: /index.html
31+
envVars:
32+
- key: VITE_SERVER_URL
33+
sync: false
34+
- key: VITE_SUPABASE_URL
35+
value: https://0ec90b57d6e95fcbda19832f.supabase.co
36+
- key: VITE_SUPABASE_ANON_KEY
37+
sync: false

server/index.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,26 @@ import cors from 'cors';
55

66
const app = express();
77
const server = createServer(app);
8+
9+
const allowedOrigins = [
10+
"http://localhost:5173",
11+
"https://localhost:5173",
12+
"http://localhost:5174",
13+
"https://securecomm.netlify.app",
14+
process.env.FRONTEND_URL
15+
].filter(Boolean);
16+
817
const io = new Server(server, {
918
cors: {
10-
origin: ["http://localhost:5173", "https://securecomm.netlify.app"],
11-
methods: ["GET", "POST"]
19+
origin: (origin, callback) => {
20+
if (!origin || allowedOrigins.includes(origin) || origin.includes('render.com')) {
21+
callback(null, true);
22+
} else {
23+
callback(new Error('Not allowed by CORS'));
24+
}
25+
},
26+
methods: ["GET", "POST"],
27+
credentials: true
1228
}
1329
});
1430

src/hooks/useSocket.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,17 @@ export function useSocket({
3838

3939
// Determine server URL based on environment
4040
const getServerUrl = () => {
41+
// Check for environment variable first
42+
const envServerUrl = import.meta.env.VITE_SERVER_URL;
43+
if (envServerUrl) {
44+
return envServerUrl;
45+
}
46+
4147
// In development, use localhost
4248
if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') {
4349
return 'http://localhost:3001';
4450
}
45-
51+
4652
// In production, use the deployed server
4753
return 'https://panger-chat-server.onrender.com';
4854
};

0 commit comments

Comments
 (0)