Add a sitemap to help search engines find all video content

Add a new GET endpoint to '/sitemap.xml' that generates an XML sitemap containing all video pages, improving SEO discoverability.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 2cd2c0bc-434c-4bc9-ad3f-b99d3897a0d1
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/2cd2c0bc-434c-4bc9-ad3f-b99d3897a0d1/gjpMN2A
This commit is contained in:
sebastjanartic 2025-09-03 15:08:38 +00:00
parent 846157a617
commit f97edf35f4

View File

@ -1270,6 +1270,42 @@ export async function registerRoutes(app: Express): Promise<Server> {
}
});
// SEO - Sitemap XML with all video pages
app.get('/sitemap.xml', async (req, res) => {
try {
const videos = await storage.getVideos(1, 1000); // Get all videos
const baseUrl = 'https://go4.video';
let sitemap = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>${baseUrl}/</loc>
<changefreq>daily</changefreq>
<priority>1.0</priority>
<lastmod>${new Date().toISOString().split('T')[0]}</lastmod>
</url>`;
// Add all video pages
videos.forEach(video => {
sitemap += `
<url>
<loc>${baseUrl}/video/${video.id}</loc>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
<lastmod>${video.updatedAt ? video.updatedAt.toISOString().split('T')[0] : new Date().toISOString().split('T')[0]}</lastmod>
</url>`;
});
sitemap += '\n</urlset>';
res.set('Content-Type', 'application/xml');
res.send(sitemap);
} catch (error) {
console.error('Error generating sitemap:', error);
res.status(500).send('Error generating sitemap');
}
});
const httpServer = createServer(app);
return httpServer;
}