Skip to content

Commit

Permalink
Added ejs rendering of pubnub file + new startup params
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudsj committed Oct 7, 2010
1 parent 0f2142d commit 8884642
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ npm:
bin/npm config set root ${PWD}/.node_libraries

npmmods:
bin/npm install vows@latest;
bin/npm install express;
bin/npm install redis;

bin/npm install vows@stable;
bin/npm install express@stable;
bin/npm install ejs@stable;
bin/npm install redis@stable;
21 changes: 19 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ app.configure(function(){
//app.use(express.cookieDecoder());
//app.use(express.session());
app.use(app.router);
app.use(express.staticProvider(__dirname + '/public'));
app.set('view engine', 'ejs');
app.set('view options', {
layout: false
});
/*app.use(express.staticProvider(__dirname + '/public'));*/
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
redPublisher.flushdb();
});
Expand All @@ -32,6 +36,19 @@ app,get('pubnub-x-origin', function(req, res)
});
*/

app.get('/pubnub.js', function(req, res)
{
res.contentType('application/javascript');
res.render('pubnub.ejs', {
locals: {
hostname: process.argv[4],
port: process.argv[3]
}
})
});



app.get('/pubnub-time', function(req, res)
{
pubnubResponse = {
Expand Down Expand Up @@ -241,6 +258,6 @@ app.get('/', function(req, res)

});

app.listen(process.argv[2]);
app.listen(process.argv[3]);

sys.log("pubnub server is now listening on: "+process.argv[2]+ ":" + process.argv[3]);
1 change: 1 addition & 0 deletions dump.rdb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REDIS0001�
2 changes: 1 addition & 1 deletion public/pubnub.js → views/pubnub.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ window.PUBNUB||function(){window.console||(window.console=window.console||{});co
c,a[c])}function A(a,b){b.call(a,a);for(a=a.firstChild;a;){A(a,b);a=a.nextSibling}}var D=/\$?{([\w\-]+)}/g;function r(a,b,c){f(a.split(","),function(e){function o(i){if(!i)i=window.event;if(!c(i)){i.cancelBubble=true;i.returnValue=false;i.preventDefault&&i.preventDefault();i.stopPropagation&&i.stopPropagation()}}if(b.addEventListener)b.addEventListener(e,o,false);else if(b.attachEvent)b.attachEvent("on"+e,o);else b["on"+e]=o})}function h(){return y("head")[0]}function p(a,b){if(!a)return"";var c=
[],e="";for(e in a)c.push(escape(e)+"="+escape(a[e]));return(b.indexOf("?")===-1?"?":"&")+c.join("&")}function g(a){return document.createElement(a)}var l=0;function j(a){if(l)return x(a);var b=g("script"),c="x"+s(),e=100,o=setTimeout(function(){C("timeout")},a.timeout||3E4),i=a.url,m=a.data||{},q=a.c||w(),v=a.b||w();function t(){setTimeout(function(){e*=2;try{var u=h(),E=u.firstChild;E?u.insertBefore(b,E):u.appendChild(b)}catch(F){t()}},e)}function C(u){clearTimeout(o);if(b){u&&q.call(u,b,unescape(b.src));
b.onerror=null;try{h().removeChild(b)}catch(E){}}}b.async="async";window[c]=function(u){if(!u)return C("no data");v.call(b,u);window[c]=null;C(0)};r("error",b,function(){C("error")});m.unique=c;b.src=i+p(m,i);t();return C}var z=/^window\[[^\]]+\]\((.+?)\)$/;function x(a){var b=window.ActiveXObject?new window.ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest,c=a.c||w(),e=a.b||w(),o=0,i=a.data||{},m=a.url,q=setInterval(function(){if(b&&b.readyState==4&&!o){var t=b.status;o=1;if(q){clearInterval(q);
q=null}t>=200&&t<300||t==304||t==1223?e(JSON.parse(b.responseText.replace(z,"$1"))):c(b);b=null}},14);i.unique="x"+s();try{b.open("GET",m+p(i,m),true);b.send()}catch(v){l=0;return j(a)}return function(){o=1;b&&b.abort&&b.abort()}}var k="http://127.0.0.1:8080/",d={history:function(a,b){b=b||w();a.limit=a.limit||100;if(!a.channel)return n("Must Specify a Channel");a.channel=d.d+"/"+a.channel;j({url:k+"pubnub-history",data:a,b:function(c){b(c.messages)},c:function(c){n(c)}})},time:function(a){j({url:k+"pubnub-time",
q=null}t>=200&&t<300||t==304||t==1223?e(JSON.parse(b.responseText.replace(z,"$1"))):c(b);b=null}},14);i.unique="x"+s();try{b.open("GET",m+p(i,m),true);b.send()}catch(v){l=0;return j(a)}return function(){o=1;b&&b.abort&&b.abort()}}var k="http://<%=hostname%>:<%=port%>/",d={history:function(a,b){b=b||w();a.limit=a.limit||100;if(!a.channel)return n("Must Specify a Channel");a.channel=d.d+"/"+a.channel;j({url:k+"pubnub-history",data:a,b:function(c){b(c.messages)},c:function(c){n(c)}})},time:function(a){j({url:k+"pubnub-time",
b:function(b){a(b.time)},c:function(){a(0)}})},uuid:function(a){j({url:k+"pubnub-uuid",b:function(b){a(b.uuid)},c:function(){a(0)}})},publish:function(a,b){b=b||w()||a.callback;var c=a.message;if(!c)return n("Must Specify a Message");if(!a.channel)return n("Must Specify a Channel");c=JSON.stringify(c);if(c.length>1700)return n("Message exceeded limit 1700");if(!d.g)return n("Missing Publish Key");a.publish_key=d.g;a.channel=d.d+"/"+a.channel;a.message=c;j({url:k+"pubnub-publish",data:a,b:function(e){b(e)},
c:function(e){b(e)}})},unsubscribe:function(a){a=d.d+"/"+a.channel;if(a in d.a){d.a[a].disabled=1;d.a[a].e=0;d.a[a].f&&d.a[a].f(0)}},h:0,i:[],subscribe:function(a,b){function c(){setTimeout(function(){i*=2;j({url:k+"pubnub-subscribe",data:a,b:function(q){q&&q.server?e(q.server):c()},c:function(){c()}})},i)}function e(q){if(!(m in d.a&&d.a[m].disabled))d.a[m].f=j({url:"http://"+q+"/",data:{channel:m,timetoken:o},b:function(v){o=v.timetoken;e(q);v.messages[0]!="xdr.timeout"&&f(v.messages,function(t){b(t)})},
c:function(v){v=="timeout"?e(q):c()}})}if(!d.h)return d.i.push([a,b]);if(!a.channel)return n("Must Specify a Channel");b=b||a.callback;delete a.callback;if(!b)return n("Must Specify a Callback");if(!d.d)return n("Missing Subscribe Key");var o=0,i=100,m=a.channel=d.d+"/"+a.channel;m in d.a||(d.a[m]={});if(d.a[m].e)return n("Already Connected to this Channel: "+m);d.a[m].disabled=0;d.a[m].e=1;c()},g:"7795f1ac-fa60-414e-b01a-0d5ec643b4cb",d:"752a4eb0-b502-11df-a256-2f52a4db9804",j:"",a:{},xdr:j,each:f,map:function(a,b){var c=[];f(a||[],function(e,
Expand Down

0 comments on commit 8884642

Please sign in to comment.