This is my setup.
- I have WordPress installed on domain root folder mydomain.com
- I have my nodejs server listening to port 3000 and installed in mydomain.com/server/ folder
- I do not have access to use virtualhosts or change apache config
Here is my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^server/(.*)?$ http://127.0.0.1:3000/$1 [P,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I still can't access my nodejs server from browser or do a call to it from my script (whether its ajax or socket.io)
Please if anyone got a work around for this problem, I've been trying to solve it without any success.
EDIT: This is my server.js
var express = require('express');
var path = require('path');
var mysql = require('mysql');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
var db = require('./db');
var operators = new Array;
// socket.io connection
io.on('connection', function(socket){
socket.emit('login', { operators: operators });
});
// Request chat button
app.get('/get_button/:key', function(req, res){
db.connect(function(err){ if (err){ throw err; } else { console.log('DB connected'); }});
db.query('select * from `wp_oboxchat_keys` where `key` = `' + req.params.key + '` limit 1', function(err, result) {
if (err) {
throw err;
} else {
res.sendFile(path.join(__dirname, '../', 'app/widget.html'));
console.log('DB successful query: get_button');
}
});
});
// Listen to server
server.listen(3000, function(){ console.log('Server started.'); });
The server runs without any errors on my console with node server.js but its not accessible from a web browser.