Skip to content

Instantly share code, notes, and snippets.

@tzuryby
Forked from wheresalice/dotcloud_build.yml
Created April 6, 2011 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzuryby/905623 to your computer and use it in GitHub Desktop.
Save tzuryby/905623 to your computer and use it in GitHub Desktop.
www:
requirements:
- faye
- jade
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);
!!! 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']);
message['text'] = message['text'].replace(/<.*?>/g,'');
$('<li>' + message['text'] + '</li>').appendTo('ul#messages');
$('html,body').animate({ scrollTop: document.height }, 'slow');
});
$('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')
[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