Skip to content

Commit 2898d7a

Browse files
Added logger
1 parent a30cc9f commit 2898d7a

60 files changed

Lines changed: 3248 additions & 505 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.local.example

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Example .env for LOCAL DEVELOPMENT with MinIO
2+
3+
PORT=8000
4+
CORS_ORIGIN=http://localhost:5173
5+
6+
# MongoDB
7+
MONGODB_URI=mongodb+srv://ytuser:ytuser1234@cluster0.evj0l.mongodb.net
8+
9+
# JWT
10+
ACCESS_TOKEN_EXPIRY=30m
11+
REFRESH_TOKEN_EXPIRY=7d
12+
ACCESS_TOKEN_SECRET=your_secret_here
13+
REFRESH_TOKEN_SECRET=your_different_secret_here
14+
15+
# Cloudinary (Primary Storage)
16+
CLOUDINARY_CLOUD_NAME=dmoyyrmxr
17+
CLOUDINARY_API_KEY=314874596436248
18+
CLOUDINARY_API_SECRET=SqgNEIl400g6fy4d1LXcM6WdY4k
19+
20+
# Local S3 with MinIO (Fallback Storage)
21+
USE_LOCAL_S3=true
22+
LOCAL_S3_ENDPOINT=http://localhost:9000
23+
AWS_REGION=us-east-1
24+
AWS_ACCESS_KEY_ID=minioadmin
25+
AWS_SECRET_ACCESS_KEY=minioadmin
26+
AWS_S3_BUCKET_NAME=stremora-videos
27+
28+
# Email
29+
SMTP_HOST=smtp.gmail.com
30+
SMTP_PORT=587
31+
SMTP_USER=avatarpatil009@gmail.com
32+
SMTP_PASS=ejxthjsuwczasoat
33+
SMTP_FROM_EMAIL=avatarpatil009@gmail.com
34+
FRONTEND_URL=http://localhost:5173
35+
36+
# Google OAuth
37+
GOOGLE_CLIENT_ID=your_google_client_id
38+
GOOGLE_CLIENT_SECRET=your_google_client_secret
39+
40+
NODE_ENV=development

.env.production.example

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Example .env for PRODUCTION with Real AWS S3
2+
3+
PORT=8000
4+
CORS_ORIGIN=https://stremora.chinmaypatil.com
5+
6+
# MongoDB
7+
MONGODB_URI=mongodb+srv://ytuser:ytuser1234@cluster0.evj0l.mongodb.net
8+
9+
# JWT
10+
ACCESS_TOKEN_EXPIRY=30m
11+
REFRESH_TOKEN_EXPIRY=7d
12+
ACCESS_TOKEN_SECRET=your_secret_here
13+
REFRESH_TOKEN_SECRET=your_different_secret_here
14+
15+
# Cloudinary (Primary Storage)
16+
CLOUDINARY_CLOUD_NAME=dmoyyrmxr
17+
CLOUDINARY_API_KEY=314874596436248
18+
CLOUDINARY_API_SECRET=SqgNEIl400g6fy4d1LXcM6WdY4k
19+
20+
# Real AWS S3 (Fallback Storage)
21+
USE_LOCAL_S3=false
22+
AWS_REGION=us-east-1
23+
AWS_ACCESS_KEY_ID=your_real_aws_key
24+
AWS_SECRET_ACCESS_KEY=your_real_aws_secret
25+
AWS_S3_BUCKET_NAME=stremora-videos
26+
27+
# Email
28+
SMTP_HOST=smtp.gmail.com
29+
SMTP_PORT=587
30+
SMTP_USER=avatarpatil009@gmail.com
31+
SMTP_PASS=ejxthjsuwczasoat
32+
SMTP_FROM_EMAIL=avatarpatil009@gmail.com
33+
FRONTEND_URL=https://stremora.chinmaypatil.com
34+
35+
# Google OAuth
36+
GOOGLE_CLIENT_ID=your_google_client_id
37+
GOOGLE_CLIENT_SECRET=your_google_client_secret
38+
39+
NODE_ENV=production

AWS_S3_SETUP.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# AWS S3 Setup Guide
2+
3+
Your app now uses a hybrid storage system:
4+
- **Primary**: Cloudinary (tries first)
5+
- **Fallback**: AWS S3 (if Cloudinary fails)
6+
7+
## Quick Setup
8+
9+
### 1. Install AWS SDK
10+
11+
```bash
12+
bun add @aws-sdk/client-s3
13+
```
14+
15+
### 2. Create AWS Account
16+
17+
Go to https://aws.amazon.com/ and sign up (free tier available)
18+
19+
### 3. Create S3 Bucket
20+
21+
1. Go to AWS Console → S3
22+
2. Click "Create bucket"
23+
3. Bucket name: `stremora-videos` (must be globally unique)
24+
4. Region: `us-east-1` (or your preferred region)
25+
5. **Uncheck "Block all public access"** ⚠️ Important!
26+
6. Click "Create bucket"
27+
28+
### 4. Set Bucket Policy (Make Files Public)
29+
30+
1. Go to your bucket → Permissions → Bucket Policy
31+
2. Click "Edit" and paste this (replace `stremora-videos` with your bucket name):
32+
33+
```json
34+
{
35+
"Version": "2012-10-17",
36+
"Statement": [
37+
{
38+
"Effect": "Allow",
39+
"Principal": "*",
40+
"Action": "s3:GetObject",
41+
"Resource": "arn:aws:s3:::stremora-videos/*"
42+
}
43+
]
44+
}
45+
```
46+
47+
3. Click "Save changes"
48+
49+
### 5. Create IAM User (Get API Keys)
50+
51+
1. Go to AWS Console → IAM → Users
52+
2. Click "Add users"
53+
3. Username: `stremora-uploader`
54+
4. Select "Access key - Programmatic access"
55+
5. Click "Next: Permissions"
56+
6. Click "Attach existing policies directly"
57+
7. Search and select: **AmazonS3FullAccess**
58+
8. Click through to create user
59+
9. **IMPORTANT**: Copy the Access Key ID and Secret Access Key (you won't see them again!)
60+
61+
### 6. Add to .env File
62+
63+
Add these to your `.env`:
64+
65+
```env
66+
# AWS S3 Configuration (Fallback Storage)
67+
AWS_REGION=us-east-1
68+
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
69+
AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
70+
AWS_S3_BUCKET_NAME=stremora-videos
71+
```
72+
73+
### 7. Test It!
74+
75+
Restart your server:
76+
77+
```bash
78+
bun run dev
79+
```
80+
81+
Upload a video and watch the logs:
82+
83+
```
84+
📤 [Storage] Attempting Cloudinary upload first...
85+
⚠️ [Storage] Cloudinary failed, trying S3 fallback...
86+
✅ [Storage] S3 fallback successful!
87+
📦 Storage provider: s3
88+
```
89+
90+
## How It Works
91+
92+
```
93+
Upload Video
94+
95+
Try Cloudinary First
96+
97+
Success? → Use Cloudinary ✅
98+
99+
Failed? → Try S3 Fallback
100+
101+
Success? → Use S3 ✅
102+
103+
Both Failed? → Error ❌
104+
```
105+
106+
## Cost
107+
108+
### AWS Free Tier (First 12 Months):
109+
- 5 GB storage
110+
- 20,000 GET requests
111+
- 2,000 PUT requests
112+
- 100 GB data transfer out
113+
114+
### After Free Tier:
115+
- Storage: ~$0.023/GB/month
116+
- Requests: $0.0004 per 1,000 GET, $0.005 per 1,000 PUT
117+
- Transfer: $0.09/GB
118+
119+
**Example**: 100 videos (10GB) + 10k views/month = ~$1.50/month
120+
121+
Much cheaper than Cloudinary's paid plans!
122+
123+
## Troubleshooting
124+
125+
### "Access Denied" Error
126+
127+
**Problem**: Bucket policy not set correctly
128+
129+
**Solution**:
130+
1. Go to bucket → Permissions → Bucket Policy
131+
2. Make sure the policy allows public read (see step 4 above)
132+
3. Verify "Block all public access" is OFF
133+
134+
### "Credentials Not Found" Error
135+
136+
**Problem**: AWS credentials not in .env
137+
138+
**Solution**:
139+
1. Check `.env` has AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
140+
2. Restart your server after adding credentials
141+
142+
### Files Upload But Can't Access
143+
144+
**Problem**: Bucket policy doesn't allow public read
145+
146+
**Solution**:
147+
1. Check bucket policy (step 4)
148+
2. Verify ACL is set to "public-read" in upload
149+
3. Try accessing the URL directly in browser
150+
151+
### "Bucket Not Found" Error
152+
153+
**Problem**: Bucket name mismatch or wrong region
154+
155+
**Solution**:
156+
1. Verify bucket name in .env matches exactly
157+
2. Check region is correct
158+
3. Make sure bucket exists in AWS Console
159+
160+
## Monitoring Usage
161+
162+
Check your AWS usage:
163+
1. Go to AWS Console → Billing Dashboard
164+
2. View "Free Tier" usage
165+
3. Set up billing alerts (recommended!)
166+
167+
## Security Best Practices
168+
169+
1. **Never commit .env to git** (already in .gitignore)
170+
2. **Use IAM user** (not root account)
171+
3. **Limit permissions** (only S3, not full AWS access)
172+
4. **Rotate keys** periodically
173+
5. **Set up billing alerts** to avoid surprises
174+
175+
## Need Help?
176+
177+
- AWS Documentation: https://docs.aws.amazon.com/s3/
178+
- AWS Free Tier: https://aws.amazon.com/free/
179+
- Support: AWS has excellent documentation and community support
180+
181+
Your hybrid storage system is now ready! Videos will automatically fall back to S3 when Cloudinary has issues. 🚀

0 commit comments

Comments
 (0)