Add a sitemap and robots.txt file for improved search engine visibility

Integrate sitemap.xml and robots.txt endpoints into the application's routing to enhance SEO by providing search engines with a structured overview of the website's content and navigation rules.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 401e2ec0-e00d-4f10-9d0e-60f3d479f9a5
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 60e60a5e-14ae-4811-88e9-d8e805dff609
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/60d372ff-2c10-46c7-b01b-10c3435136b0/401e2ec0-e00d-4f10-9d0e-60f3d479f9a5/a97MHcj
This commit is contained in:
sebastjanartic 2026-01-24 12:55:06 +00:00
parent b042acc538
commit e6b387e613
2 changed files with 74 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 973 KiB

View File

@ -272,6 +272,80 @@ export async function registerRoutes(app: Express): Promise<Server> {
});
});
// Sitemap.xml for SEO
app.get("/sitemap.xml", async (req, res) => {
try {
const baseUrl = "https://video.folx.tv";
const videos = await storage.getVideos(1000, 0);
// Helper to escape XML special characters
const escapeXml = (str: string) => {
if (!str) return '';
return str
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;');
};
let xml = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url>
<loc>${baseUrl}/</loc>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
`;
for (const video of videos) {
const shortId = video.id.replace(/-/g, '').substring(0, 8);
const lastmod = video.createdAt ? new Date(video.createdAt).toISOString().split('T')[0] : new Date().toISOString().split('T')[0];
const safeTitle = escapeXml(video.title);
const safeDescription = escapeXml(video.description || video.title);
const safeThumbnail = escapeXml(video.thumbnailUrl || '');
xml += ` <url>
<loc>${baseUrl}/video/${shortId}</loc>
<lastmod>${lastmod}</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
<video:video>
<video:thumbnail_loc>${safeThumbnail}</video:thumbnail_loc>
<video:title>${safeTitle}</video:title>
<video:description>${safeDescription}</video:description>
<video:duration>${video.duration || 0}</video:duration>
</video:video>
</url>
`;
}
xml += `</urlset>`;
res.setHeader('Content-Type', 'application/xml');
res.setHeader('Cache-Control', 'public, max-age=3600');
res.send(xml);
} catch (error) {
console.error('Error generating sitemap:', error);
res.status(500).send('Error generating sitemap');
}
});
// Robots.txt
app.get("/robots.txt", (req, res) => {
const baseUrl = "https://video.folx.tv";
const robots = `User-agent: *
Allow: /
Disallow: /admin
Disallow: /api/
Sitemap: ${baseUrl}/sitemap.xml
`;
res.setHeader('Content-Type', 'text/plain');
res.send(robots);
});
app.get("/api/auth/me", authenticate, async (req, res) => {
try {
const user = await storage.getUser(req.session.userId!);