• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Node.js sample application with Socket.IO


コミットメタ情報

リビジョンa71631aece2b041c01ff0217d702e2d3d9a313be (tree)
日時2012-10-23 23:47:27
作者hylom <hylom@hylo...>
コミッターhylom

ログメッセージ

add codes for socket.io

変更サマリ

差分

--- a/app.js
+++ b/app.js
@@ -6,7 +6,8 @@
66 var express = require('express')
77 , routes = require('./routes')
88 , http = require('http')
9- , path = require('path');
9+ , path = require('path')
10+ , socketIO = require('socket.io');
1011
1112 var app = express();
1213
@@ -28,7 +29,11 @@ app.configure('development', function(){
2829
2930 app.get('/', routes.index);
3031 app.post('/room', routes.room);
32+app.get('/echo/:name', routes.echo);
3133
32-http.createServer(app).listen(app.get('port'), function(){
34+var server = http.createServer(app);
35+var io = socketIO.listen(server);
36+
37+server.listen(app.get('port'), function(){
3338 console.log("Express server listening on port " + app.get('port'));
3439 });
--- a/public/css/style.css
+++ b/public/css/style.css
@@ -25,4 +25,8 @@ a {
2525
2626 .message .author {
2727 font-weight: bold;
28-}
\ No newline at end of file
28+}
29+
30+.message .comment {
31+ word-wrap: break-word;
32+}
--- a/routes/index.js
+++ b/routes/index.js
@@ -1,22 +1,42 @@
1-
21 /*
32 * GET home page.
43 */
54
5+var crypto = require('crypto');
6+
67 exports.index = function(req, res){
78 res.render('index', { title: 'minichat' });
89 };
910
11+exports.echo = function(req, res) {
12+ var params = {
13+ title: 'チャットルーム:' + req.params.name,
14+ room: {
15+ name: req.params.name,
16+ password: ''
17+ },
18+ user: {name: ''}
19+ };
20+ res.render('room', params);
21+};
22+
1023 exports.room = function(req, res){
1124 var roomName = req.body.roomName || '';
1225 var yourName = req.body.yourName || '';
1326 var password = req.body.password || '';
27+ var hashedPassword = '';
28+ var shasum = crypto.createHash('sha512');
29+
30+ if (password !== '') {
31+ shasum.update(password);
32+ hashedPassword = shasum.digest('hex');
33+ }
1434
1535 var params = {
1636 title: 'チャットルーム:' + roomName,
1737 room: {
1838 name: roomName,
19- password: password
39+ password: hashedPassword
2040 },
2141 user: {name: yourName}
2242 };
--- a/views/layout.jade
+++ b/views/layout.jade
@@ -7,5 +7,6 @@ html
77 script(src='/js/jquery-1.8.2.min.js')
88 script(src='/js/minichat.js')
99 script(src='/js/bootstrap.min.js')
10+ script(src='/socket.io/socket.io.js')
1011 body
11- block content
\ No newline at end of file
12+ block content
--- a/views/room.jade
+++ b/views/room.jade
@@ -24,7 +24,7 @@ block content
2424 .message
2525 p.postdate.pull-right 10/23 12:34
2626 p.author システムメッセージ:
27- p.comment チャットルーム「hogehoge」が作成されました。
27+ p.comment チャットルーム「hogehoge」が作成されました。HASH: #{room.password}
2828 hr
2929 footer
3030 p minichat 0.0.1
\ No newline at end of file