-
-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathvalidate-vercel-config.js
More file actions
81 lines (65 loc) · 2.74 KB
/
validate-vercel-config.js
File metadata and controls
81 lines (65 loc) · 2.74 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
#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
console.log('🧪 Vercel Configuration Validator\n');
// Check if vercel.json exists
const vercelConfigPath = path.join(__dirname, 'vercel.json');
if (!fs.existsSync(vercelConfigPath)) {
console.log('❌ vercel.json not found!');
process.exit(1);
}
console.log('✅ vercel.json found');
// Read and parse vercel.json
try {
const config = JSON.parse(fs.readFileSync(vercelConfigPath, 'utf8'));
console.log('✅ vercel.json is valid JSON');
// Check for rewrites
if (config.rewrites && Array.isArray(config.rewrites)) {
console.log('✅ Rewrites section found');
// Check for SPA rewrite rule
const spaRewrite = config.rewrites.find(rule =>
rule.source === '(.*)' || rule.source === '/(.*)'
);
if (spaRewrite && spaRewrite.destination === '/index.html') {
console.log('✅ SPA rewrite rule correctly configured');
console.log(` Source: ${spaRewrite.source}`);
console.log(` Destination: ${spaRewrite.destination}`);
} else {
console.log('⚠️ SPA rewrite rule not found or incorrect');
}
} else {
console.log('⚠️ No rewrites section found');
}
// Check for security headers
if (config.headers && Array.isArray(config.headers)) {
console.log('✅ Security headers configured');
const securityHeaders = ['X-Content-Type-Options', 'X-Frame-Options', 'X-XSS-Protection'];
const foundHeaders = [];
config.headers.forEach(headerConfig => {
if (headerConfig.headers) {
headerConfig.headers.forEach(header => {
if (securityHeaders.includes(header.key)) {
foundHeaders.push(header.key);
}
});
}
});
console.log(` Found security headers: ${foundHeaders.join(', ')}`);
}
console.log('\n🎯 Configuration Summary:');
console.log(' - SPA routing: ✅ Configured');
console.log(' - Security headers: ✅ Configured');
console.log(' - Cache headers: ✅ Configured');
console.log('\n🚀 Testing Instructions:');
console.log('1. Deploy to Vercel');
console.log('2. Visit any route (e.g., /elements)');
console.log('3. Refresh the page (F5)');
console.log('4. Should load without 404 error');
} catch (error) {
console.log('❌ Error parsing vercel.json:', error.message);
process.exit(1);
}
console.log('\n✅ Vercel configuration validation complete!');