0

I am facing the following issue, using nodejs and react on a Wamp server. I have to mention that I do not render my React app using the express server. I have 500 internal error when inspecting in browser and GET /socket.io/?EIO=3&transport=polling&t=NSPfrNh 404 on backend, but I think the main issue is from the Apache, whos virtual host looks like this:

<VirtualHost *:8085>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot "${INSTALL_DIR}/frontend"
  <Directory "${INSTALL_DIR}/frontend/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
    Require all granted
    #Require local
  </Directory>
ProxyRequests off
        ProxyVia on
        RewriteEngine On

        RewriteEngine On
        RewriteCond %{HTTP:Connection} Upgrade [NC]
        RewriteCond %{HTTP:Upgrade} websocket [NC]
        RewriteRule /(.*) ws://http://machineIp:8085/$1 [P,L]

        ProxyPass               / http://machineIp:8085/
        ProxyPassReverse        / http://machineIp:8085/



</VirtualHost>

But when I checked the appache error log I see the following message: No protocol handler was valid for the URL /socket.io/ (scheme 'https'). If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule., referer: http://machineIp:8085/ticketalocation

Here is my backend nodejs code:

var cors = require('cors')
const express       = require('express');
const path          = require('path');
const cookieParser  = require('cookie-parser');
const logger        = require('morgan');
const passport      = require('passport')
const session       = require('express-session')
const winston = require('winston');
const indexRouter   = require('./routes/index');
const authRouter    = require('./routes/auth');
const apiRouter     = require('./routes/api');
const app = express();
const httpServer = http.createServer(app);

const io = require('socket.io')();

io.on('connection', (client) => {
  client.on('subscribeToTimer', (interval) => {
    console.log('client is subscribing to timer with interval ', interval);
    setInterval(() => {
      client.emit('timer', new Date());
    }, interval);
  });
});

const port = 8085;
io.listen(port);
console.log('listening on port ', port);
app.use(function (req, res, next) {
  res.header('Access-Control-Allow-Origin', 'http://machineIP:8085');
  res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept-Type');
  res.header('Access-Control-Allow-Credentials', 'true');
  next();
})

And here is my client React code - api.js:

import openSocket from 'socket.io-client';
const  socket = openSocket('http://machineIp:8085');
function subscribeToTimer(cb) {
  socket.on('timer', timestamp => cb(null, timestamp));
  socket.emit('subscribeToTimer', 1000);
}
export { subscribeToTimer };

Which I use in other js file- TicketAllocation:

import { subscribeToTimer } from "../../API/api.js";


class TicketAlocation extends React.Component {
  constructor(props) {
    super(props);
   
    const { cookies } = props;
    this.state = {
     
      timestamp: 'no timestamp yet'
    };
    subscribeToTimer((err, timestamp) => this.setState({ 
      timestamp 
    }));
                      }
    
render() {

  return (
    <div>
     <p>
          This is the timer value: {this.state.timestamp}
    </p>
    </div>
  );
}
  }
iulia_g31
  • 13
  • 5
  • Does this answer your question? [WebSockets and Apache proxy : how to configure mod\_proxy\_wstunnel?](https://stackoverflow.com/questions/27526281/websockets-and-apache-proxy-how-to-configure-mod-proxy-wstunnel) – Thomas Sablik Jan 19 '21 at 08:54
  • Partially yes, but I still have 500 proxy error on browser. I've checked the error apache logs: [proxy:error] [pid 7556:tid 1300] (20014)Internal error (specific information not available): [client ipMachine:58801] AH01084: pass request body failed to [::1]:5001 (localhost), referer: http://ipMachine:8085/ticketalocation [Tue Jan 19 15:43:27.242450 2021] [proxy:error] [pid 7556:tid 1300] [client ipMachine:58801] AH00898: Error during SSL Handshake with remote server returned by /socket.io/, referer: http://ipMachine:8085/ticketalocation [proxy_http:error] [pid 7556:tid 1300] – iulia_g31 Jan 19 '21 at 14:10

0 Answers0