// В server.js добавьте перед app.listen

app.get('/sitemap.xml', async (req, res) => {
    try {
        const properties = await new Promise((resolve, reject) => {
            db.all("SELECT id, updatedAt FROM properties ORDER BY id DESC", [], (err, rows) => {
                if (err) reject(err);
                else resolve(rows);
            });
        });
        
        const baseUrl = 'https://kvartiry-anapa.ru';
        const now = new Date().toISOString();
        
        let sitemap = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
        <loc>${baseUrl}/</loc>
        <lastmod>${now}</lastmod>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>`;
        
        properties.forEach(prop => {
            sitemap += `
    <url>
        <loc>${baseUrl}/property.html?id=${prop.id}</loc>
        <lastmod>${prop.updatedAt || now}</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.8</priority>
    </url>`;
        });
        
        sitemap += `
</urlset>`;
        
        res.header('Content-Type', 'application/xml');
        res.send(sitemap);
    } catch (err) {
        res.status(500).send('Error generating sitemap');
    }
});