-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-prerender.js
More file actions
111 lines (93 loc) · 3.1 KB
/
Copy pathtest-prerender.js
File metadata and controls
111 lines (93 loc) · 3.1 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
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env node
/**
* Test script to verify prerendering setup
* Run: node test-prerender.js
*/
import fetch from 'node-fetch';
const API_URL = 'https://api.iosas.online';
console.log('\n🧪 Testing Prerender Configuration\n');
console.log('═'.repeat(50) + '\n');
async function testAPIConnection() {
console.log('1️⃣ Testing API connection...');
try {
const response = await Promise.race([
fetch(`${API_URL}/announcements`),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Timeout after 10s')), 10000)
)
]);
if (response.ok) {
const data = await response.json();
console.log(` ✅ API reachable`);
console.log(` 📢 Found ${data.announcements?.length || 0} announcements\n`);
return data.announcements || [];
} else {
console.log(` ⚠️ API returned status ${response.status}\n`);
return [];
}
} catch (error) {
console.log(` ❌ API connection failed: ${error.message}\n`);
return [];
}
}
async function testOrganizations() {
console.log('2️⃣ Testing organizations endpoint...');
try {
const response = await Promise.race([
fetch(`${API_URL}/organizations`),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Timeout after 10s')), 10000)
)
]);
if (response.ok) {
const data = await response.json();
console.log(` ✅ Organizations reachable`);
console.log(` 🏢 Found ${data.organizations?.length || 0} organizations\n`);
return data.organizations || [];
} else {
console.log(` ⚠️ API returned status ${response.status}\n`);
return [];
}
} catch (error) {
console.log(` ❌ Organizations fetch failed: ${error.message}\n`);
return [];
}
}
async function main() {
const announcements = await testAPIConnection();
const organizations = await testOrganizations();
const staticRoutes = [
'/', '/about', '/forms', '/calendar', '/developers',
'/organizations', '/faqs', '/bug', '/privacy-policy',
'/terms-of-service', '/auth-complete'
];
const dynamicRoutes = [
...announcements.map(a => `/announcements/${a.id}`),
...organizations.map(o => `/organizations/${o.id}`)
];
const totalRoutes = staticRoutes.length + dynamicRoutes.length;
console.log('═'.repeat(50));
console.log('\n📊 Summary\n');
console.log(` Static routes: ${staticRoutes.length}`);
console.log(` Dynamic routes: ${dynamicRoutes.length}`);
console.log(` Total routes: ${totalRoutes}\n`);
if (dynamicRoutes.length > 0) {
console.log('✅ Pre-rendering will work!\n');
console.log(' Example dynamic routes:');
dynamicRoutes.slice(0, 5).forEach(route => {
console.log(` • ${route}`);
});
if (dynamicRoutes.length > 5) {
console.log(` ... and ${dynamicRoutes.length - 5} more\n`);
} else {
console.log('');
}
} else {
console.log('⚠️ No dynamic routes found (API may be down)\n');
console.log(' Static routes will still be pre-rendered.\n');
}
console.log('Next steps:');
console.log(' 1. Run `npm run build` to test regular build');
console.log(' 2. Run `npm run build:prerender` for full pre-rendering\n');
}
main().catch(console.error);