Look up "Apache reverse proxy" - that is how you map an apache request to your
nodejs port. In my case, I am mapping a whole domain, so each request going to
mydomain.com:80 is initially going to mydomain.com:8080
Am Do. Feb. 20 2014 14:01:07 schrieb gyanesh gouraw:
> How am i supposed to run my node.js code on apache server, which is currently
> using localhost and port 5000 to apache server,port 8080.
> This is my serverside code chatserver.js
>
> var httpd = require('http').createServer(handler);
> var io = require('socket.io').listen(httpd);
> var fs = require('fs');
>
> httpd.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);
> });
> });
>
>
>
> //This is my client side code. index.html
>
>
> <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>
>
> 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>
>
> --
--
--
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.