From a8a362ffbc0ad9f15affcccf11068273a7c8ffd0 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Sat, 14 Jan 2017 02:26:21 +0300 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B0=D0=BD=D1=82=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 31 +++++++++++++++++++++++-------- package.json | 1 + phantom.js | 3 ++- src/torrent-page.js | 4 ++-- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index d48c4e6..f2e0f4d 100644 --- a/index.js +++ b/index.js @@ -8,9 +8,13 @@ var app = express(); var server = require('http').Server(app); var io = require('socket.io')(server); var sm = require('sitemap'); +var phantomjs = require('phantomjs-prebuilt') const torrentTypeDetect = require('./lib/content'); +const domain = process.env.NODE_ENV == 'production' ? 'ratsontheboat.org' : 'localhost:3000'; +const http_port = 8095; + const mysqlSettings = { host : 'localhost', user : 'btsearch', @@ -24,7 +28,7 @@ const sphinxSettings = { }; // Start server -server.listen(8095); +server.listen(http_port); let socketMysql = mysql.createPool({ connectionLimit: 40, @@ -82,11 +86,6 @@ function handleListenerDisconnect() { handleListenerDisconnect(); -app.get('/', function(req, res) -{ - res.sendfile(__dirname + '/build/index.html'); -}); - app.use(express.static('build')); app.get('/sitemap.xml', function(req, res) { @@ -95,7 +94,7 @@ app.get('/sitemap.xml', function(req, res) { return; } let sitemap = sm.createSitemap ({ - hostname: 'http://ratsontheboat.org', + hostname: 'http://' + domain, cacheTime: 600000 }); sitemap.add({url: '/'}); @@ -114,7 +113,23 @@ app.get('/sitemap.xml', function(req, res) { app.get('*', function(req, res) { - res.sendfile(__dirname + '/build/index.html'); + if(typeof req.query['_escaped_fragment_'] != 'undefined') + { + let program = phantomjs.exec('phantom.js', 'http://' + domain + req.path) + let body = ''; + program.stderr.pipe(process.stderr) + program.stdout.on('data', (chunk) => { + body += chunk; + }); + program.on('exit', code => { + res.header('Content-Type', 'text/html'); + res.send( body ); + }) + + return; + } + + res.sendfile(__dirname + '/build/index-page.html'); }); // start diff --git a/package.json b/package.json index af11152..86fb4de 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "moment": "^2.17.1", "mysql": "^2.12.0", "page": "^1.7.1", + "phantomjs-prebuilt": "^2.1.14", "react": "^15.4.1", "react-dom": "^15.4.1", "react-tap-event-plugin": "^2.0.1", diff --git a/phantom.js b/phantom.js index 1db9015..33b266e 100644 --- a/phantom.js +++ b/phantom.js @@ -1,4 +1,5 @@ -var url = "http://localhost:3000/"; +var system = require('system'); +var url = system.args[1]; var page = require('webpage').create(); page.open(url, function(status) { diff --git a/src/torrent-page.js b/src/torrent-page.js index 818ea88..803b291 100644 --- a/src/torrent-page.js +++ b/src/torrent-page.js @@ -139,13 +139,13 @@ export default class TorrentPage extends Page { }); }; componentDidMount() { - window.torrentSocket.emit('torrent', this.props.hash, {files: true}, (data) => { + window.torrentSocket.emit('torrent', this.props.hash, {files: true}, window.customLoader((data) => { if(data) { this.torrent = data this.setTitle('Download ' + this.torrent.name); this.forceUpdate(); } - }); + })); } render() { return (