a6da045e19
- Refactored product categories to use a new data structure. - Updated API routes to fetch product categories from the new data source. - Implemented sitemap generation script using dotenv for environment variables. - Added sitemap generation endpoint to the API. - Removed old sitemap file and replaced it with a dynamically generated one.
37 lines
922 B
TypeScript
37 lines
922 B
TypeScript
// scripts/generate-sitemap.ts
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const http = require('http');
|
|
require('dotenv').config();
|
|
|
|
const API_PATH = '/api/sitemapBuilder';
|
|
const DEST_PATH = path.join(process.cwd(), 'public', 'sitemap.xml');
|
|
|
|
function fetchSitemap(): Promise<string> {
|
|
return new Promise((resolve, reject) => {
|
|
http
|
|
.get(
|
|
`${process.env.VERCEL_PROJECT_PRODUCTION_URL}${API_PATH}`,
|
|
(res: any) => {
|
|
let data = '';
|
|
|
|
res.on('data', (chunk: any) => (data += chunk));
|
|
res.on('end', () => resolve(data));
|
|
},
|
|
)
|
|
.on('error', reject);
|
|
});
|
|
}
|
|
|
|
(async () => {
|
|
try {
|
|
const xml = await fetchSitemap();
|
|
|
|
fs.writeFileSync(DEST_PATH, xml, 'utf8');
|
|
console.log('✅ Sitemap generated at public/sitemap.xml');
|
|
} catch (err) {
|
|
console.error('❌ Failed to generate sitemap:', err);
|
|
process.exit(1);
|
|
}
|
|
})();
|