ibrahimlasfar commited on
Commit
278e59d
ยท
1 Parent(s): fbf7bdc

Fix sitemap.xml dynamic generation

Browse files
Files changed (1) hide show
  1. server.js +49 -11
server.js CHANGED
@@ -15,6 +15,7 @@ const multer = require('multer');
15
  const MGZonStrategy = require('passport-mgzon');
16
  const { jsPDF } = require('jspdf');
17
  const Jimp = require('jimp');
 
18
 
19
  const path = require('path');
20
  require('jspdf-autotable');
@@ -4073,18 +4074,55 @@ app.get('/terms', (req, res) => {
4073
 
4074
  // Sitemap.xml
4075
  app.get('/sitemap.xml', (req, res) => {
4076
- const filePath = path.join(__dirname, 'public', 'sitemap.xml');
4077
- if (fs.existsSync(filePath)) {
4078
- res.sendFile(filePath);
4079
- } else {
4080
- // ุงู„ูƒูˆุฏ ุงู„ุฏูŠู†ุงู…ูŠูƒูŠ ุงู„ู„ูŠ ุนู†ุฏูƒ
4081
- const baseUrl = process.env.BASE_URL || 'https://mgzon-server.hf.space';
4082
- const sitemap = `...`;
4083
- res.header('Content-Type', 'application/xml');
4084
- res.send(sitemap);
4085
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4086
  });
4087
-
4088
  // Robots.txt
4089
  app.get('/robots.txt', (req, res) => {
4090
  const robots = `User-agent: *
 
15
  const MGZonStrategy = require('passport-mgzon');
16
  const { jsPDF } = require('jspdf');
17
  const Jimp = require('jimp');
18
+ const fs = require('fs');
19
 
20
  const path = require('path');
21
  require('jspdf-autotable');
 
4074
 
4075
  // Sitemap.xml
4076
  app.get('/sitemap.xml', (req, res) => {
4077
+ const baseUrl = process.env.BASE_URL || 'https://mgzon-server.hf.space';
4078
+ const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
4079
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
4080
+ <url>
4081
+ <loc>${baseUrl}/</loc>
4082
+ <lastmod>${new Date().toISOString().split('T')[0]}</lastmod>
4083
+ <changefreq>daily</changefreq>
4084
+ <priority>1.0</priority>
4085
+ </url>
4086
+ <url>
4087
+ <loc>${baseUrl}/api-docs</loc>
4088
+ <lastmod>${new Date().toISOString().split('T')[0]}</lastmod>
4089
+ <changefreq>weekly</changefreq>
4090
+ <priority>0.8</priority>
4091
+ </url>
4092
+ <url>
4093
+ <loc>${baseUrl}/privacy</loc>
4094
+ <lastmod>${new Date().toISOString().split('T')[0]}</lastmod>
4095
+ <changefreq>monthly</changefreq>
4096
+ <priority>0.5</priority>
4097
+ </url>
4098
+ <url>
4099
+ <loc>${baseUrl}/terms</loc>
4100
+ <lastmod>${new Date().toISOString().split('T')[0]}</lastmod>
4101
+ <changefreq>monthly</changefreq>
4102
+ <priority>0.5</priority>
4103
+ </url>
4104
+ <url>
4105
+ <loc>${baseUrl}/api/health</loc>
4106
+ <lastmod>${new Date().toISOString().split('T')[0]}</lastmod>
4107
+ <changefreq>hourly</changefreq>
4108
+ <priority>0.3</priority>
4109
+ </url>
4110
+ <url>
4111
+ <loc>${baseUrl}/api/projects</loc>
4112
+ <lastmod>${new Date().toISOString().split('T')[0]}</lastmod>
4113
+ <changefreq>daily</changefreq>
4114
+ <priority>0.7</priority>
4115
+ </url>
4116
+ <url>
4117
+ <loc>${baseUrl}/api/skills</loc>
4118
+ <lastmod>${new Date().toISOString().split('T')[0]}</lastmod>
4119
+ <changefreq>weekly</changefreq>
4120
+ <priority>0.6</priority>
4121
+ </url>
4122
+ </urlset>`;
4123
+ res.header('Content-Type', 'application/xml');
4124
+ res.send(sitemap);
4125
  });
 
4126
  // Robots.txt
4127
  app.get('/robots.txt', (req, res) => {
4128
  const robots = `User-agent: *