-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-vercel-env.js
More file actions
101 lines (91 loc) · 3.38 KB
/
setup-vercel-env.js
File metadata and controls
101 lines (91 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env node
/**
* Automated Vercel Environment Variables Setup Script
* This script automatically configures all required environment variables for the JobConnect application
*/
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
// Environment variables configuration
const envVars = {
MONGODB_URI: 'mongodb+srv://aryabratmishra:jobsforarya2023@cluster0.mongodb.net/jobconnect?retryWrites=true&w=majority',
JWT_SECRET: '36718b6c5e943c88a46822b12f94b6b35ecc1514b24255181e7b57cf36d1eb0d072b7c80f7642c1e097f4659293abe22d8b97f68afadcf35560053c79d468ff7',
JWT_EXPIRE: '7d',
NODE_ENV: 'production',
CLIENT_URL: 'https://jobcon-six.vercel.app',
API_BASE_URL: 'https://jobcon-six.vercel.app/api',
PORT: '5000'
};
console.log('🚀 JobConnect - Vercel Environment Setup');
console.log('=====================================\n');
// Check if Vercel CLI is installed
try {
execSync('vercel --version', { stdio: 'pipe' });
console.log('✅ Vercel CLI detected');
} catch (error) {
console.log('❌ Vercel CLI not found. Installing...');
try {
execSync('npm install -g vercel', { stdio: 'inherit' });
console.log('✅ Vercel CLI installed successfully');
} catch (installError) {
console.error('❌ Failed to install Vercel CLI. Please install manually: npm install -g vercel');
process.exit(1);
}
}
// Login to Vercel (if not already logged in)
console.log('\n🔐 Checking Vercel authentication...');
try {
execSync('vercel whoami', { stdio: 'pipe' });
console.log('✅ Already authenticated with Vercel');
} catch (error) {
console.log('🔑 Please login to Vercel...');
try {
execSync('vercel login', { stdio: 'inherit' });
console.log('✅ Successfully authenticated with Vercel');
} catch (loginError) {
console.error('❌ Failed to authenticate with Vercel');
process.exit(1);
}
}
// Set environment variables
console.log('\n⚙️ Setting up environment variables...');
for (const [key, value] of Object.entries(envVars)) {
try {
console.log(`Setting ${key}...`);
execSync(`vercel env add ${key} production`, {
input: `${value}\ny\n`,
stdio: ['pipe', 'pipe', 'inherit']
});
console.log(`✅ ${key} set successfully`);
} catch (error) {
// Try to update if variable already exists
try {
console.log(`Updating existing ${key}...`);
execSync(`vercel env rm ${key} production`, {
input: 'y\n',
stdio: ['pipe', 'pipe', 'inherit']
});
execSync(`vercel env add ${key} production`, {
input: `${value}\ny\n`,
stdio: ['pipe', 'pipe', 'inherit']
});
console.log(`✅ ${key} updated successfully`);
} catch (updateError) {
console.log(`⚠️ ${key} might already exist or failed to set`);
}
}
}
// Trigger redeployment
console.log('\n🔄 Triggering redeployment...');
try {
execSync('vercel --prod', { stdio: 'inherit' });
console.log('✅ Redeployment triggered successfully');
} catch (error) {
console.log('⚠️ Manual redeployment may be required');
}
console.log('\n🎉 Environment setup completed!');
console.log('\n📋 Summary:');
console.log('- All environment variables configured');
console.log('- Production deployment triggered');
console.log('- Your app should be live at: https://jobcon-six.vercel.app');
console.log('\n⏰ Please wait 2-3 minutes for deployment to complete.');