Created
April 6, 2011 11:55
-
-
Save gertig/905525 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
www: | |
requirements: | |
- faye | |
- jade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'), | |
faye = require('faye'), | |
jade = require ('jade'), | |
fs = require('fs'); | |
var template = fs.readFileSync('index.jade', 'utf8'); | |
var bayeux = new faye.NodeAdapter({ | |
mount: '/faye', | |
timeout: 45 | |
}); | |
// Handle non-Bayeux requests | |
var server = http.createServer(function(request, response) { | |
response.writeHead(200, {'Content-Type': 'text/html'}); | |
//response.write(Haml.render(haml)); | |
response.write(jade.render(template)); | |
response.end(); | |
}); | |
bayeux.attach(server); | |
server.listen(8080); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!!! 5 | |
html(lang="en") | |
head | |
title= "Node/Faye/Jade Tech Demo" | |
link(href='http://cachedcommons.org/cache/blueprint/0.9.1/stylesheets/screen-min.css', type='text/css', rel='stylesheet') | |
script(type='text/javascript', src='http://cachedcommons.org/cache/jquery/1.4.2/javascripts/jquery-min.js') | |
script(type='text/javascript', src='http://fayechat.kaerast.info/faye.js') | |
script(type='text/javascript') | |
$(function() { | |
var client = new Faye.Client('http://fayechat.kaerast.info/faye'); | |
var subscription = client.subscribe('/messages', function(message) { | |
//alert('recieved ' + message['text']); | |
$('<li>' + message['text'].replace(/<\/?[^>]+(>|$)/g, "") + '</li>').appendTo('ul#messages'); | |
}); | |
$('form#compose').submit(function() { | |
sendmessage(); | |
}); | |
function sendmessage() { | |
var compose = $('input[name$="compose"]').val(); | |
client.publish('/messages', {text: compose}); | |
$('input[name$="compose"]').val(''); | |
$('input[name$="compose"]').focus(); | |
//alert('sending ' + compose); | |
}; | |
$('input[name$="compose"]').focus(); | |
}); | |
body | |
.container | |
h1 Node/Faye/Jade Tech Demo | |
p | |
| Uses | |
a(href='http://www.dotcloud.com') Dotcloud | |
| for hosting, | |
a(href='http://nodejs.org') Node.js | |
| as the server, | |
a(href='http://faye.jcoglan.com/') Faye | |
| for pub/sub and | |
a(href='http://jade-lang.com/') Jade | |
| for template rendering | |
p | |
| Source code is available in | |
a(href='https://gist.github.com/901738') git | |
| . We also have a shiney API (for free): | |
p | |
code curl http://fayechat.kaerast.info/faye -d 'message={"channel":"/messages", "data":{"text":"hello world"}}' | |
ul#messages | |
li messages will appear here | |
form#compose(action='javascript:return false;') | |
input(type='text', name='compose') | |
input(type='submit', name='send', value='send') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[program:node] | |
command = node faye.js | |
directory = /home/dotcloud/current |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment