javascript - implement Nodejs app in already existing website -
i want place chatroom i've crated in node.js existing website. node.js has been installed lamp server , i've tried app uploading root directory , testing works accessing typing address site followed port :3000
inside vpns www/html
directory have folder called chat want become chat website.
in here have file called index.php
serves me login , register page , when logged in redirected home.php
, location want nodejs chat placed.
my page looks this:
the whitespace can see under blue bar place want chat appear.
so first of question how node.js application run in target area , question how make node application visible in specific area.
to make things simple i've reduced code socket.io example chat code.
var app = require('express')(); var http = require('http').server(app); var io = require('socket.io')(http); app.get('/', function(req, res){ res.sendfile(__dirname + '/chat.html'); //behlver itne senda html igentligen kan bara skriva hela fuckign koden // min home.php fil tillsammans med alla scripts etc etc }); io.on('connection', function(socket){ socket.on('chat message', function(msg){ io.emit('chat message', msg); }); }); http.listen(3000, function(){ console.log('listening on *:3000'); });
and html document sends called chat.html looks simple this:
<div class="chatwrapper"> <ul id="messages"> </ul> <form action=""> <input id="m" autocomplete="off" /><button>send</button> </form> </div> <script src="https://cdn.socket.io/socket.io-1.2.0.js"></script> <script src="/socket.io/socket.io.js"></script> <script src="http://code.jquery.com/jquery-1.11.1.js"></script> <script> var socket = io(); $('form').submit(function(){ socket.emit('chat message', $('#m').val()); $('#m').val(''); return false; }); socket.on('chat message', function(msg){ $('#messages').append($('<li>').text(msg)); }); </script>
i'd put iframe
on chat.php
page points node chat.html
.
<iframe src="http://example.com:3000/chat.html"></iframe>
https://developer.mozilla.org/en-us/docs/web/html/element/iframe
Comments
Post a Comment