From 4a4c37e3a50c8ec3c18bd0608b80f6bb844f4055 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Sat, 14 Jan 2017 01:30:23 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=B0=D1=80=D1=82=D0=B0=20=D1=81=D0=B0?= =?UTF-8?q?=D0=B9=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 25 ++++++++++++++++++++++++- package.json | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 75e550a..d48c4e6 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ var express = require('express'); var app = express(); var server = require('http').Server(app); var io = require('socket.io')(server); +var sm = require('sitemap'); const torrentTypeDetect = require('./lib/content'); @@ -88,12 +89,34 @@ app.get('/', function(req, res) app.use(express.static('build')); +app.get('/sitemap.xml', function(req, res) { + socketMysql.query('SELECT hash FROM `torrents`', function (error, rows, fields) { + if(!rows) { + return; + } + let sitemap = sm.createSitemap ({ + hostname: 'http://ratsontheboat.org', + cacheTime: 600000 + }); + sitemap.add({url: '/'}); + for(let i = 0; i < rows.length; i++) + sitemap.add({url: '/torrent/' + rows[i].hash}); + + sitemap.toXML( function (err, xml) { + if (err) { + return res.status(500).end(); + } + res.header('Content-Type', 'application/xml'); + res.send( xml ); + }); + }); +}); + app.get('*', function(req, res) { res.sendfile(__dirname + '/build/index.html'); }); - // start io.on('connection', function(socket) diff --git a/package.json b/package.json index 3e2ab67..af11152 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "react": "^15.4.1", "react-dom": "^15.4.1", "react-tap-event-plugin": "^2.0.1", + "sitemap": "^1.9.0", "socket.io": "^1.7.2" }, "scripts": {