This node.js code is running on my localhost but when i am running it on 
Apache server with mod_proxy and mod_http_proxy enabled it gives me the 
source code of the chatserver rather than executing it. I have modified my 
conf file so that it proxies every request to port 5000(for testing 
purpose). Now I have 2 questions: 1)Why do I get the static chatserver page 
when I open localhost:5000? 2)Why do I get the source code of the 
chatserver when I open localhost?
 server code:

var http = require('http').createServer(handler);
var io = require('socket.io').listen(http);
var fs = require('fs');

http.listen(5000);

function handler(req, res) {
  fs.readFile(__dirname + '/index.html',
    function(err, data) {
      if (err) {
       res.writeHead(500);
       return res.end('Error loading index.html');
      }

      res.writeHead(200);
      res.end(data);
    }
  );
}

io.sockets.on('connection', function (socket) {
  socket.on('clientMessage', function(content) {
    socket.emit('serverMessage', 'You said: ' + content);
    socket.broadcast.emit('serverMessage', socket.id + ' said: ' + 
      content);
  });
});


index.htmlcode

<html>
  <head>
    <title>Node.js WebSocket chat</title>
    <style type="text/css">
      #input {
        width: 200px;
      }
      #messages {
        position: fixed;
        top: 40px;
        bottom: 8px;
        left: 8px;
        right: 8px;
        border: 1px solid #EEEEEE;
        padding: 8px;
      }
    </style>
  </head>

  <body>
<h1> Your link to other page</h1>
<a href = "http://www.facebook.com";>Facebook</a>
    Your message:
    <input type="text" id="input">

    <div id="messages"></div>

    <script src="http://localhost:5000/socket.io/socket.io.js";></script>
    <script type="text/javascript">
      var messagesElement = document.getElementById('messages');
      var lastMessageElement = null;

      function addMessage(message) {
        var newMessageElement = document.createElement('div');
        var newMessageText = document.createTextNode(message);

        newMessageElement.appendChild(newMessageText);
        messagesElement.insertBefore(newMessageElement, 
          lastMessageElement);
        lastMessageElement = newMessageElement;
      }

      var socket = io.connect('http://localhost:5000');
      socket.on('serverMessage', function(content) {
        addMessage(content);
      });

      var inputElement = document.getElementById('input');

      inputElement.onkeydown = function(keyboardEvent) {
        if (keyboardEvent.keyCode === 13) {
          socket.emit('clientMessage', inputElement.value);
          inputElement.value = '';
          return false;
        } else {
          return true;
        }
      };
    </script>

  </body>
</html>

conf file:

My conf file modification is
 ProxyRequests off 
<Proxy *> Order deny,allow Allow from all </Proxy>
 <Location /> 
ProxyPass localhost:5000 ProxyPassReverse localhost:5000 </Location> 
</VirtualHost> – 


-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to