sitemap и тд

This commit is contained in:
Georgiy Syralev
2025-11-01 12:29:46 +03:00
parent 727785c7a0
commit d45baf2260
80 changed files with 9811 additions and 748 deletions

View File

@@ -13,13 +13,12 @@ dotenv.config();
const app = express();
// ИСПРАВЛЕНО: более точная настройка CORS
app.use(cors({
origin: [
'http://localhost:3000',
'http://localhost:5173',
'https://ospab.host'
], // Vite обычно использует 5173
],
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization']
@@ -27,7 +26,6 @@ app.use(cors({
app.use(express.json());
// Добавим логирование для отладки
app.use((req, res, next) => {
console.log(`${new Date().toISOString()} - ${req.method} ${req.path}`);
next();
@@ -36,7 +34,6 @@ app.use((req, res, next) => {
import { checkProxmoxConnection } from './modules/server/proxmoxApi';
app.get('/', async (req, res) => {
// Проверка соединения с Proxmox
let proxmoxStatus;
try {
proxmoxStatus = await checkProxmoxConnection();
@@ -53,9 +50,68 @@ app.get('/', async (req, res) => {
});
});
// ==================== SITEMAP ====================
app.get('/sitemap.xml', (req, res) => {
const baseUrl = 'https://ospab.host';
const staticPages = [
{ loc: '/', priority: '1.0', changefreq: 'weekly' },
{ loc: '/about', priority: '0.9', changefreq: 'monthly' },
{ loc: '/tariffs', priority: '0.95', changefreq: 'weekly' },
{ loc: '/login', priority: '0.7', changefreq: 'monthly' },
{ loc: '/register', priority: '0.8', changefreq: 'monthly' },
{ loc: '/terms', priority: '0.5', changefreq: 'yearly' },
{ loc: '/privacy', priority: '0.5', changefreq: 'yearly' },
];
let xml = '<?xml version="1.0" encoding="UTF-8"?>\n';
xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n';
for (const page of staticPages) {
xml += ' <url>\n';
xml += ` <loc>${baseUrl}${page.loc}</loc>\n`;
xml += ` <priority>${page.priority}</priority>\n`;
xml += ` <changefreq>${page.changefreq}</changefreq>\n`;
xml += ' </url>\n';
}
xml += '</urlset>';
res.header('Content-Type', 'application/xml');
res.send(xml);
});
// ==================== ROBOTS.TXT ====================
app.get('/robots.txt', (req, res) => {
const robots = `User-agent: *
Allow: /
Allow: /about
Allow: /tariffs
Allow: /login
Allow: /register
Allow: /terms
Disallow: /dashboard
Disallow: /api/
Disallow: /admin
Disallow: /private
Sitemap: https://ospab.host/sitemap.xml
# Google
User-agent: Googlebot
Allow: /
Crawl-delay: 0
# Yandex
User-agent: Yandexbot
Allow: /
Crawl-delay: 0`;
res.header('Content-Type', 'text/plain; charset=utf-8');
res.send(robots);
});
// Статические файлы чеков
import path from 'path';
app.use('/uploads/checks', express.static(path.join(__dirname, '../uploads/checks')));
@@ -73,9 +129,10 @@ import { setupConsoleWSS } from './modules/server/server.console';
import https from 'https';
import fs from 'fs';
// ИСПРАВЛЕНО: используйте fullchain сертификат
const sslOptions = {
key: fs.readFileSync('/etc/apache2/ssl/ospab.host.key'),
cert: fs.readFileSync('/etc/apache2/ssl/ospab.host.crt'),
cert: fs.readFileSync('/etc/apache2/ssl/ospab.host.fullchain.crt'),
};
const httpsServer = https.createServer(sslOptions, app);
@@ -84,4 +141,6 @@ setupConsoleWSS(httpsServer);
httpsServer.listen(PORT, () => {
console.log(`🚀 HTTPS сервер запущен на порту ${PORT}`);
console.log(`📊 База данных: ${process.env.DATABASE_URL ? 'подключена' : 'НЕ НАСТРОЕНА'}`);
console.log(`📍 Sitemap доступен: https://ospab.host:${PORT}/sitemap.xml`);
console.log(`🤖 Robots.txt доступен: https://ospab.host:${PORT}/robots.txt`);
});