фантом

This commit is contained in:
Alexey Kasyanchuk
2017-01-14 02:26:21 +03:00
parent 4a4c37e3a5
commit a8a362ffbc
4 changed files with 28 additions and 11 deletions

View File

@ -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

View File

@ -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",

View File

@ -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) {

View File

@ -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 (